- Home /
Split in for loop not working after first iteration
I am trying to Split a collection of comma seperated value strings within a for loop. Using Debug after each split, it appears only the first Split gets all 14 entries of the csv. Subsequent loops display only a couple of the values after the Split. Attaching the following script to an empty game object will show these unwelcome results in the console. Is this a bug in Unity? Must I look up each comma individually and use Substring to split? Thanks!
var arrayMapItemsAll = new Array();
arrayMapItemsAll.Add("28,107,39,3,http://gqassets.s3.amazonaws.com/healthy_start.unity3d,1310769976,1394,-1.875~0~-4.375,1,1,0,0,0,0");
arrayMapItemsAll.Add("28,107,39,1,http://gqassets.s3.amazonaws.com/healthy_start.unity3d,1310769976,1393,-4.375~0~-4.375,1,1,0,0,0,0");
arrayMapItemsAll.Add("28,116,39,1,http://gqassets.s3.amazonaws.com/dead_start.unity3d,1310770799,1393,-4.375~0~-4.375,1,1,0,0,0,3");
arrayMapItemsAll.Add("99,116,39,1,http://gqassets.s3.amazonaws.com/dead_start.unity3d,1310770799,1395,-4.375~0~-4.375,1,1,0,0,0,3");
function Start () {
for (var i=0; i < arrayMapItemsAll.length; i++) {
var det1 : String[] = arrayMapItemsAll[i].Split(","[0]);
Debug.Log("arrayMapItemsAll[i] length Verify it is 14 = " + det1.length);
Debug.Log("det1[0] = "+det1[0]);
Debug.Log("det1[1] = "+det1[1]);
Debug.Log("det1[2] = "+det1[2]);
Debug.Log("det1[3] = "+det1[3]);
Debug.Log("det1[4] = "+det1[4]);
Debug.Log("det1[5] = "+det1[5]);
Debug.Log("det1[6] = "+det1[6]);
Debug.Log("det1[7] = "+det1[7]);
Debug.Log("det1[8] = "+det1[8]);
Debug.Log("det1[9] = "+det1[9]);
Debug.Log("det1[10] = "+det1[10]);
Debug.Log("det1[11] = "+det1[11]);
Debug.Log("det1[12] = "+det1[12]);
Debug.Log("det1[13] = "+det1[13]);
}
}
Answer by aldonaletto · Jul 16, 2011 at 01:50 AM
The problem probably is the damned Collapse button at the top of the Console view. I tried this script and it worked fine, but when I clicked Collapse and run it again some of the lines were not displayed.
Answer by polytropoi · Jul 16, 2011 at 01:57 AM
Arghhhh! You're the greatest! Thank You!
You're not the only one fooled by this *#$&@ Collapse button - it happens all the time! By the way, please click the "check" button below the voting thumbs in my answer to mark it as correct - it helps other people having the same problem. Another thing: in future questions use comments to reply to an answer (people will think this question has two answers, ins$$anonymous$$d of only one; don't $$anonymous$$d, it's another thing that happens all the time...)