简体   繁体   中英

String List parsing

I have a string that is like this:

Item1;Item2;Item3

but could also be

Item1

Is there a slick .net method to get that into a List?

string.split是你的朋友......

var yourString = "Item1;Item2;Item3";

var result = new List<string>(yourString.Split(';'));

LINQ has a way to bring the array to string, too:

var inputString = "item1;item2;item3";
var asList = inputString.Split( ';' ).ToList();
var input = "Item1;Item2;Item3";
var list = input.Split(new[] {";"}, StringSplitOptions.None).ToList();

Here's how I'd do that:

string[] arr = str.Split( new char[] { ';' } );
List<string> list = new List<string>( arr );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM