Hi guys i was trying a lot to retrieve some other strings from one main string.
string src = "A~B~C~D";
How can i retrieve separately the letters? Like:
string a = "A";
string b = "B";
string c = "C";
string d = "D";
you could use Split(char c) that will give you back an array of sub strings seperated by the ~ symbol.
string src = "A~B~C~D";
string [] splits = src.Split('~');
obviously though, unless you know the length of your string/words in advance you won't be able to arbitrarily put them in their own variables. but if you knew it was always 4 words, you could then do
string a = splits[0];
string b = splits[1];
string c = splits[2];
string d = splits[3];
string src = "A~B~C~D";
string[] letters = src.Split('~');
foreach (string s in letters)
{
//loop through array here...
}
string words[]=Regex.Matches(input,@"\w+")
.Cast<Match>()
.Select(x=>x.Value)
.ToArray();
\w matches a single word i.e A-Z or a-z or _ or a digit
+is a quantifier which matches preceding char 1 to many times
~and what have you tried