- Home /
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[i]);
}
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.
Answer by Dracorat · Apr 17, 2013 at 06:52 PM
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("\n", "").Split('/');
for (int i=0; i < AllPanelData.Length; i++)
{
Console.WriteLine(AllPanelData[i]);
}
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!
$$anonymous$$ake sure to accept the answer then. Glad you're on your way!
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
How to extract part of a string variable? 1 Answer
Distribute terrain in zones 3 Answers
C# String Array Has Missing or Incorrect Keycode Strings 2 Answers
Can I create a list with an int/float and a string? C# 2 Answers