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\{\/");
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First, get rid of the
whileloop. 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.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.
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.