- Home /
Question by
Samael_00001 · May 01, 2014 at 01:58 PM ·
characterstringforeach
How to get int values from a string?
I have a string, which contains numbers that interest me. There is 16 of such numbers, divided with "_" symbol. How to get them? Thanks!
P.S. I was thinking about converting this string into char array and than use foreach, but how to seperate them?
Comment
Best Answer
Answer by Professor Snake · May 01, 2014 at 02:02 PM
You can use String.Split() to split the numbers, and then int.Parse to parse them from strings. Basically:
var myString:String;//String with your numbers
var myNumbers:int[];
function DecodeString(){
var stringArray:String[]=myString.Split("_"[0]);//Split myString wherever there's a _ and make a String array out of it.
myNumbers=new int[stringArray.length];
for(var num:int=0;num<stringArray.length;num++){
myNumbers[num]=int.Parse(stringArray[num]);
}
}
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Recover deleted Character Controller.unitypackage 1 Answer
[solved] replace char with string UNITY 1 Answer
Checking whether string is a valid Input.Key 1 Answer
character joint scripting HELP!!! 1 Answer