- Home /
Question by
Bluestrike · Aug 05, 2014 at 02:15 PM ·
stringsplit
split string without a separator
How can I split a string without using a seperator? This causes an Index is out of range error.
stringVar.Split(""[0]);
Comment
What are you after? You can use this to turn that string into a char array.
A quick and easy way to convert a int value to a array of numbers. I have a int of 5 number that track if a player completed a level on a specific difficulty. Based on Paulo Henrique awnser I found out I can do string[3] and get the 3rd value.
Best Answer
Answer by Paulo-Henrique025 · Aug 05, 2014 at 02:36 PM
Strings are just Char arrays
string s = "abcdefghij";
string part1 = "";
string part2 = "";
for (int i = 0; i < s.Length; i++)
{
if(i % 2 == 0)
{
part1 += s[i].ToString();
}
else
{
part2 += s[i].ToString();
}
}
Debug.Log(part1);
Debug.Log(part2);
Output:
acegi
bdfhj