Splitting a string into an array - help

Ran into something wierd today where Debug.Log() seems to be failing where its not logging anything. As no log added at all. not even a empty one.

It seems Split is giving a error making Debug.Log Fail but yet
I’m able to read the first key in the array just fine.
Getting length on the array doesn’t work as well.

string log = "56/192 bleh bleh bleh bleh bleh";


                        string logString = log.Split(' ').First().Trim();

                        Debug.Log(logString); // This 56/192 returns correctly

                        string[] strArray = logString.Split('/');

                        Debug.Log(strArray); // does not log

                        float OverallPercentage = int.Parse(strArray[0].Trim()) / int.Parse(strArray[1].Trim());

                        Debug.Log(strArray.Length+" is the length"); // does not log

                        Debug.Log(strArray[0].Trim()); // This 56 returns correctly

                        Debug.Log(strArray[1].Trim()); // does not log

Just a guess, but it might be seeing the single / character as an escape character. Try putting two //, or use @(‘/’) Also, I generally add some text in each Debug.Log statement in addition to the variables, in case the variables are null or empty.

Thanks for the reply man.

Turns out Trim is causing the issue some how.

Debug.Log(strArray[1]); // This logs 195
Debug.Log(strArray[1].Trim()); // This doesn't log

This won’t log either @JeffDUnity3D

Debug.Log("Some text"+strArray[1].Trim()+" Some text"); // does not log

"" is the escape character, not “/”. Anyway it works fine; try putting the script into a new empty project.

–Eric

one thing i just noticed is i forgot to cast the int math to a float.
Decided to just remove the trim. Really don’t need it if im parsing to int.

float OverallPercentage = (float)int.Parse(strArray[0]) / int.Parse(strArray[1]);