[Solved] String.Split not working?

Here is my code:

var DataStr=w.data;
Data = DataStr.Split(":");
Ter = Data[0];
Owner = Data[1];

It keeps giving me this error:

Help please?

EDIT: I figured it out String.Split has to be lile this: Data = DataStr.Split(":"[0]);

2 Likes

(“:”,[0])

1 Like
	var str : String = "tom.mom.mot";
    var arr = new Array();	
	arr = str.Split(".", [0]);

// arr[0] = tom
// arr[1] = mom
1 Like

You’re too late!@Tempest :smile:

Wow I figured this out right as you guys posted…

great :slight_smile:

It’s probably clearer syntax if you type it like this:

Data = DataStr.Split(‘:’);

Split is looking for a char, so use the char quotes.

Creative’s and Tempest’s sample code is wrong.
You should write “.”[0].
You must not write comma.

Why?what’s [0]…

1 Like

it should be

 string[] Data = DataStr.Split(':');

The original code (from years ago!) is in Unityscript, so no that won’t work. “:”[0] is correct.

–Eric

1 Like

My bad, i thought that was c#.

Will pay more attention :smile: