String.Trim() and String.Split()

Having trouble understanding how these work. I know that String.Split(" "[0]); is the code you use to split text into a string array that represents each line. I cannot, however, find the appropriate documentation that explains the parameters of that form of Split(). What is the [0] for?

However, I have successfully implemented this portion and can split my text file into lines. Then I started trying to compare lines to strings expecting a match, but not getting them. For example, if my text file has three lines, say “house”, “tree”, and “car”, I would expect element [0] to == “house”, element [1] to == “tree”, and element [2] to == “car”. No joy. Then I assumed there was another special character at the end of each line, that being “\r”. How do I get the “\r” out of there? I cannot figure out how to use Trim() or Split() to do it.

This is actually a workaround in UnityScript because UnityScript doesn’t have character literals. You actually use a string (which is an array of characters) and just take the first character [0] as splitting delimiter.

However, you can also use strings to split another string, but you have to provide an array of strings as delimiter. Usually i use C#, so maybe you can write this simpler:

var myStr = "TestString

Second line";

var arr = myStr.Split(["

"], StringSplitOptions.None);

Trim should also remove lineseperators or paragraphseperators, so when you Trim each element, it should not contain any whithspace characters at the beginning or end.

arr[0] = arr[0].Trim();

Just as reference, In C# you can define char-literals like this:

string[] arr = myStr.Split('


Chars can only contain one single character. Keep in mind that in this example there is onle one character, the escape character (the backslash) isn’t a seperate character.

var strs = "house

“house” == strs[0].Trim(); // for example