- Home /
How can i separate a string in 2?
Hi, i want to separate a string in 2,
what i mean :
Lets supose i got 3 strings : MainString, String1 , String2.
in my MainString i got : Hello ; World
i want to divide it and do that i got : Hello in my String1 and : World in my String2.
using as separator the ";" sign.
idk how should i do this , but i need it .
Comment
Best Answer
Answer by ModLunar · Jun 30, 2018 at 08:04 PM
the String class has a method for this called Split, where it'll give you back an array of strings, splitting the string based on a character separator. You could do something like this:
string mainString = ": Hello ; World";
string[] tokens = mainString.Split(';');
//tokens will be of size 2, containing ": Hello " and " World".
Hopefully that helps :)