Hi! I have problems with reading a file (textasset) line by line and getting the results!
here is the file i am trying to read:
AUTHOR
COMMENT
INFO 1 X ARG 0001 0.581 2.180 1.470
INFO 2 X ARG 0001 1.400 0.974 1.724
INFO 3 X ARG 0001 2.553 0.934 0.751
INFO 4 X ARG 0001 3.650 0.494 1.053
INFO 5 X ARG 0001 1.188 3.073 1.532
INFO 6 X ARG 0001 2.312 1.415 -0.466
INFO 7 X ARG 0001 -0.232 2.249 2.180
END
here is the code i am using (file is textasset set in inspector:
//read file
string[] line = file.text.Split("\n"[0]);
for(int i = 0 ; i < line.Length ; i++)
{
if(line[i].Contains("INFO"))
{
//To replace all spaces with single underscore "_" (it works fine)
string l = System.Text.RegularExpressions.Regex.Replace(line[i]," {2,}","_");
//In this Debug.Log i get correct results
//For example "INFO_1_X_ARG_0001_0.581_2.180_1.470"
Debug.Log(l);
string[] subline = System.Text.RegularExpressions.Regex.Split(l,"_");
//Only for first "INFO" line i get correct results (INFO,1,X,ARG,0001,0.581,2.180,1.470)
//For all other "INFO" lines i get incomplete results (first,fourth and fifth element are not put into substrings
//like they are dissapeard!
foreach(string s in subline)
{
Debug.Log(s);
}
}
}
explanation,
i first split text into lines (works fine)
then i read only lines that contains “INFO”
i loop all line that contain “INFO” and replace all spaces with underscore _ (works fine)
i split lines that contain “INFO” into substrings based on underscor _
when i print out the lines only first line with “INFO” seems to have all substrings
every next line is not splitted correctly (first part “INFO” is omitted as well as third string)
it seems very unreliable, is this the way to go with these things? thanks
any help appreciated! this should be simple thing, what i am doing wrong? thank you!