Say I have:
var str = "this is a string separated by spaces";
and I did:
alert(str.split(" " , 1));
the outcome would be "this"
Whereas I want the outcome to be "this,is a string separated by spaces"
maybe split isn't the right method?
What I'm trying to do is separate a string into parts based on semicolons, unless those semicolons are in quotes. For example, I would want
randomnessstuff;morestuff;some more stuff
to be in three parts, so I've been doing:
var str = "randomnessstuff;morestuff;some more stuff";
var parts = str.split(";");
Which has been working fine, but if the semicolon is in quotes, I want it to NOT be separated into another part.
for example, with:
var str = "randomnessstuff;morestuff and a semicolon in quotes : ";";some more stuff";
I would want part 1 to be randomnessstuff
, part 2 to be morestuff and a semicolon in quotes : ";"
, and part 3 to be some more stuff
of course, if I just did split with the semicolon again, it would make part 3 the quote.
What I'm hoping to do is have a loop that checks the semicolons one by one to see if they're in quotes, and if not, to split with them. If this last bit didn't make any sense, then please just answer the first question, about using split without losing the rest of the string.