- Home /
Problem About String.Split() Function
Hi, all! I am runnig this code in unity: var member_url = "http://localhost/search.php"; var ID="2"; var action = "show"; function Start(){ var form = new WWWForm(); form.AddField( "action", action); form.AddField( "id", ID); var download = new WWW( member_url, form ); yield download;
if(download.error) {
print( "Error downloading: " + download.error );
return;
} else {
// show the data
Debug.Log(download.text);
var data = download.text;
var values = data.Split(",");//pay attention to this part
var v1 : float = parseInt(values[0]);
var v2 : float = parseInt(values[1]);
print(v1+v2);
}
}
but unity show this error: BCE0023: No appropriate version of 'String.Split' for the argument list '(String)' was found.
Answer by Kryptos · Oct 22, 2012 at 09:40 AM
Take a look at the documentation before using a method. String.Split takes an array of char as parameter, not a string.
So the correct usage is (C#):
data.Split(new char[]{','});
With UnityScript you need to use a workaround since ther are no character literals:
var separator : char[] = [","[0]];
data.Split(separator);
but what can ido with this?
var v1 : float = parseInt(values[0]); var v2 : float = parseInt(values[1]); unity error:FormatException: Input string was not in the correct format
I don't know about parseInt
. In .Net the method is named int.Parse
(see: Int32.Parse $$anonymous$$ethod (String)).
Your answer
Follow this Question
Related Questions
What do you say the best way to store a string be? 2 Answers
String.Split With Backslash 2 Answers
split() for separators more than 1 characters 2 Answers
Split webplayer build into smaller files? 1 Answer
how can you split an object in half 1 Answer