I am using a string to store country code with its cost centre code value . I want to spilit it out the string using LINQ query by | and ; characters. The srting is
IND|001;TWN|002;USA|003;LDN|;MYS|005;
Please help me to spilt out the string value using LINQ
I am assuming you need a list of Tuple<string,string>
as output.
var myString = "IND|001;TWN|002;USA|003;LDN|;MYS|005;";
var objects = myString.Split(';')
.Where(x => !string.IsNullOrEmpty(x))
.Select (x => x.Split('|'))
.Select (x => Tuple.Create(x[0],x[1]))
.ToList();
Result:
IND 001
TWN 002
USA 003
LDN
MYS 005
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