String.Split Not Splitting Correctly. Some Duplicates are being deleted.

So i’ve been trying to solve this for hours with no avail.
I try to split this string here (AllPanelData), splitting at the “/”…:
5
/0
/0
/0.82
/0
/0
/-0.82
/-0.5
/0.3
/0
/0.2
/0.2
/0.2
/0.4
/0.4
/0.4

into an array and then display it in the debug window using this:

AllPanelData = feedText.Split("/" [0]);
	for (int i=0; i<AllPanelData.Length; i++)
		{
			Debug.Log (AllPanelData*);*

}

However the debug window shows that the values of AllPanelData are:
5
0
0.82
0
-0.82
0.5
0.3
0.2
0.4
0.4
0.4

So it seems like half the characters have disappeared. This seems to happen with 0’s or duplicates (e.g. when 0.2 appears twice in the text but only set to one member of the array)
Any solution would be great.

1 Answer

1

I can’t reproduce that with your code.

Code I used (I just created a Console App since this is straight string manipulation);

string feedText = @"5
/0
/0
/0.82
/0
/0
/-0.82
/-0.5
/0.3
/0
/0.2
/0.2
/0.2
/0.4
/0.4
/0.4
";
string[] AllPanelData = feedText.Replace("\r", "").Replace("

", “”).Split(‘/’);
for (int i=0; i < AllPanelData.Length; i++)
{
Console.WriteLine(AllPanelData*);*

  • }*
    Output:
    5
    0
    0
    0.82
    0
    0
    -0.82
    -0.5
    0.3
    0
    0.2
    0.2
    0.2
    0.4
    0.4
    0.4
    Edit: Now that I think about it, I think Debug.Log sometimes hides duplicate values.
    Go to the Console window and unclick collapse.

Wow, incredibly it was that the console window had collapse checked .Everything is working fine now and i've accomplished more since fixing that than I have the rest of the entire day. Thanks!

Make sure to accept the answer then. Glad you're on your way!