How can I split a string only once, i.e. make 1|Ceci n\'est pas une pipe: | Oui parse to: [\"1\", \"Ceci n\'est pas une pipe: | Oui\"]?
1|Ceci n\'est pas une pipe: | Oui
[\"1\", \"Ceci n\'est pas une pipe: | Oui\"]
The
You'd want to use String.indexOf('|') to get the index of the first occurrence of '|'.
String.indexOf('|')
var i = s.indexOf('|'); var splits = [s.slice(0,i), s.slice(i+1)];