Best Way To Insert Char In Specific Points Of String In Javascript?
If I have the following string '[Blah][Something.][Where.]' What is the best way to locate wherever the '][' is and add a ' + ' in between them? In other words, the resulting stri
Solution 1:
Using regular expressions...
var str = "[Blah][Something.][Where.]"var newString = str.replace(/\]\[/g, ']+[');
Solution 2:
varstring = "[Blah][Something.][Where.]".split("][").join("] + [");
If it was not a constant string, I would fallback to a regular expression and replace.
Solution 3:
Use regular expresions to find ][ and then add +
Post a Comment for "Best Way To Insert Char In Specific Points Of String In Javascript?"