Reputation: 62674
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 string should be:
"[Blah] + [Something.] + [Where.]"
Upvotes: 1
Views: 2764
Reputation: 23075
var string = "[Blah][Something.][Where.]".split("][").join("] + [");
If it was not a constant string, I would fallback to a regular expression and replace.
Upvotes: 1
Reputation: 26134
Using regular expressions...
var str = "[Blah][Something.][Where.]"
var newString = str.replace(/\]\[/g, ']+[');
Upvotes: 2