- Home /
Question is off-topic or not relevant - string.split is fully documented elsewhere
One more String.Split question
I need to split a string as below:
var pname = lines[i].Split("x3C"[0])[1];
and I can not get the results I expect, no matter what I put instead of "0" in "[0]". This problem was discussed here many times, but in the cases I have found, the splitting string was always one character long.
Graham beat me to posting a link to where it's documented. But he's right; it's not a Unity question.
I has been asked and answered a few times here anyway. I wouldn't ask if it was working as explained here: http://www.w3schools.com/jsref/jsref_split.asp
That's the problem with you guys... You still don't realise that you don't work with browser JScript. UnityScript is a Javascript-syntax-based language but it is compiled with $$anonymous$$ono / .Net
string.Split can only split by a single char. You can't use a string as splitting delimiter. In Unityscript you can't define char-literals that's why you have to use a string and than grab the single char via index.
"x3C"[0] == 'x'
"x3C"[1] == '3'
"x3C"[2] == 'C'
You ARE dealing with something that's pretty well documented in the $$anonymous$$SDN. The function you want is documented here: http://msdn.microsoft.com/en-us/library/tabh47cf.aspx#Y500 That is, you can split a string by another string. Oddly, I don't see a simple 'string by A string' but 'string by array of strings' (like the one mentioned above is for an array of chars. I don't know how they program in Redmond, but most of us would be fine with a single string or char API.
Follow this Question
Related Questions
How to split a string using unity flash player? 0 Answers
Grab part of a string by looking for keyword 2 Answers
String.Split("¦"[0]) is not finding character 1 Answer
Parse String and Serialise 1 Answer
String Split all characters? 1 Answer