Home > Blockchain >  How do i split string into a List, but there are different symbols to be split by
How do i split string into a List, but there are different symbols to be split by

Time:10-05

This is the string i want to split: "Pesho=11;Gosho=4". I want this string to be 4 separate elements in a List:Pesho , 11, Gosho, 4. How do i do that?

CodePudding user response:

String.Split has overloads that takes an array of separators:

var result = "Pesho=11;Gosho=4".Split(new []{'=', ';'}, StringSplitOptions.RemoveEmptyEntries);

CodePudding user response:

Simply do a Split() on it, should solve your issue like so:

var results = "Pesho=11;Gosho=4".Split('=', ';');
  •  Tags:  
  • c#
  • Related