- Home /
"Extract" from a string
lets say I have this string:
var rawData : String = "Joe ; 99 ; Bacon";
How can I convert this string to a string array?
I know a possible way but I've no idea how to code it
if rawData.Find ";" then the previous letters (Joe) goes to a newArray[1] etc..
Answer by whydoidoit · Apr 19, 2013 at 05:33 PM
You need to use String.Split -
var array = rawData.Split(";"[0]);
But that will leave the spaces in - if you don't want them you'd need to do something like this:
import System.Linq;
var array = rawData.Split(";"[0]).Select(function(c) c.Trim()).ToArray();
but doesn't that result in "Joe 99 Bacon" I want: var one = "Joe"; var two = "99"; var three = "Bacon";
btw thanks for your reply
That results in array[0] = "Joe", array[1] = "99", array[2] = "Bacon"
You can split using strings ins$$anonymous$$d of chars, so this would also work:
var array = rawData.Split([" ; "], System.StringSplitOptions.RemoveEmptyEntries);
Your answer
Follow this Question
Related Questions
Get JSON array object string value 2 Answers
Convert String to GameObject[] type Array 2 Answers
Array - Convert Object into Int 5 Answers
Converting a string to an int 2 Answers
Convert Array to String 3 Answers