I want to get the substring XXX and ZZZ from my result text in c#
Text form: ("; XXX; ZZZ; WWW") but
Result.LastIndexOf(";")
Does not affect because I have ";" char for separate two word
and I can't find index of first and second ";" char in my word.
Split input string using string.Split() and remove spaces around using string.Trim():
var str = "; XXX; ZZZ; WWW";
var parts = str.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
.Select(x => x.Trim());
foreach (var part in parts)
Console.WriteLine(parts);
Result is exactly as asked in the question and without empty values:
XXX
ZZZ
WWW
Here is the solution. Just split it by the special character.
string x = "; XXX; ZZZ; WWW";
string[] y = x.Split(';');
Now you have
y[0] = "";
y[1] = " XXX";
y[2] = " ZZZ";
y[3] = " WWW";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With