Hello,
I have a string that I need to be split, so that each of the values can go into an array. Here is an example of it:
12345
67890
I tried using this code to put the values in an array.
var myTextFile : TextAsset;
function Awake(){
for (var x = 0; x< myTextFile.text.Length; x++){
if (myTextFile.text[x] != myTextFile.text[5]) {
if(myTextFile.text[x] != "
"){
intArray.Push(myTextFile.text);
}
}
}
}
When reading the values, they are not integers. I did not parse them because I don’t know how to split it without any delimiters. (i.e String.Split(“”[0]) I always had to change it to put commas between the numbers and use “,” as a separator. Is there a way I can get around this?
Something like this(found in another answer):
var lineArray : String [] = myTextFile.text.Split("
"[0]);
for ( var thisLine : String in lineArray ) {
var numberStrings : String [] = thisLine.Split(""[0]);
for ( var thisNumber : String in numberStrings ) {
var someInt : int = int.Parse(thisNumber);
intArray.Push(someInt);
}
}
my workaround to this was to make the textFile toString. After that I just compared the string values to see if it matched.
myStr = myTextFile.text[x].ToString();
intArray.Push(myStr);
Not exactly an intArray anymore though. (stringArray)