I'm trying to split a huge string that uses "}, {" as it's separator.
If I use the following code will I get split it into it's own string?
var i;
var arr[];
while(str) {
arr[i] = str.split("/^}\,\s\{\/");
}
I'm trying to split a huge string that uses "}, {" as it's separator.
If I use the following code will I get split it into it's own string?
var i;
var arr[];
while(str) {
arr[i] = str.split("/^}\,\s\{\/");
}
First, get rid of the while loop. Strings are immutable, so it won't change, so you'll have an infinite loop.
Then, you need to get rid of the quotation marks to use regex literal syntax and get rid of the ^ since that anchors the regex to the start of the string.
/},\s\{/
Or just don't use a regex at all if you can rely on that exact sequence of characters. Use a string delimiter instead.
"}, {"
Also, this is invalid syntax.
var arr[];
So you just do the split once, and you'll end up with an Array of strings.
All in all, you want something like this.
var arr = str.split(/*your split expression*/)
}, { in the string that should not be a split token, then .split() won't work in general unless there's some other characters to differentiate them.