explode string

Hi!

How can I explode a string to an array?
E.g:

myString = "blah.unityweb?var1=hello&var2=hahaha";
myArray = explode ("?",myString);

Output:

myArray[0]="blah.unityweb";
myArray[1]="var1=hello&var2=hahaha";

If it’s c# this way:

myString = "blah.unityweb?var1=hello&var2=hahaha";
char[] separator = { '?' };
myArray = myString.Split(separator);

Thanks! However, I use Javascript, it seems that Split or split is not a member of String :-/

Yeah, you have to use C#. Javascript has a String.split() function, but its not supported in Unity :frowning: There are a stack of javascript string functions missing, but you have the entire C# string function set.

Yikes! IMHO a bit weird that simple string functions like this are unsuported!

For more info (for people who searched for this topic):
http://forum.unity3d.com/viewtopic.php?t=2275&highlight=split

You can use the C# syntax right in your javascript code though. Just make sure you type cast your variables.

Things like: Substring instead of substr. Length instead of length. It’s annoying, but you get used to it :slight_smile:

Hmmm I didn’t know that :smile:

It fails on this line though:
char[ ] separator = { ‘?’ };

Unexpected char: “”.

dacloo: I cant tell you about the split function syntax, but I do know we have it working at work in Turret Wars. When I get to work on Monday, I will send you a code snippet… If you can wait that long.

Thanks to Freyr, the answer to this query can be found here:
http://forum.unity3d.com//viewtopic.php?p=37853#37853