Skip to content
Advertisement

Tag: substring

How to get text after the 9th occurrence of a character using javascript?

I got the following string: NPA-Woodburn,OR,Woodburn,OR,97071,Bensenville,IL,60106,150.00,0.00,cash/certified funds,,enclosed,operable,,,,, I need to loop through some rows and sum the 9th text after “,”, but I just can’t get to it. I’ve seen many combinations of solutions, but none gets me there. Thank you. Answer You can split the string by that character, remove all items in the array before the 9th item

What value does a substring have if it doesn’t exist?

I have a string, msg. I want to check if the third character in the string exists or not. I’ve tried if (msg.substring(3, 4) == undefined) { … } but this doesn’t work. What would the substring be equal to if it does not exist? Answer The third character of the string exists if the string has three characters, so

Substring text with HTML tags in Javascript

Do you have solution to substring text with HTML tags in Javascript? For example: Answer Taking into consideration that parsing html with regex is a bad idea, here is a solution that does just that 🙂 EDIT: Just to be clear: This is not a valid solution, it was meant as an exercise that made very lenient assumptions about the

How to trim a file extension from a String in JavaScript?

For example, assuming that x = filename.jpg, I want to get filename, where filename could be any file name (Let’s assume the file name only contains [a-zA-Z0-9-_] to simplify.). I saw x.substring(0, x.indexOf(‘.jpg’)) on DZone Snippets, but wouldn’t x.substring(0, x.length-4) perform better? Because, length is a property and doesn’t do character checking whereas indexOf() is a function and does character

Advertisement