Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent to String.Split that returns a generic list?

I'd like to do something like this:

Dim Foo as String = "a,b,c,d,e"
Dim Boo as List(of String) = Foo.Split(","c)

Of course Foo.Split returns a one-dimensional array of String, not a generic List. Is there a way to do this without iterating through the array to turn it into a generic List?

like image 990
Herb Caudill Avatar asked Oct 14 '08 15:10

Herb Caudill


People also ask

How do you split a list of strings?

Python String split() MethodThe split() method splits a string into a list. You can specify the separator, default separator is any whitespace. Note: When maxsplit is specified, the list will contain the specified number of elements plus one.

How to Split a string into multiple strings?

split() The method split() splits a String into multiple Strings given the delimiter that separates them. The returned object is an array which contains the split Strings. We can also pass a limit to the number of elements in the returned array.

How to Split string with as delimiter?

Using String. split() Method. The split() method of the String class is used to split a string into an array of String objects based on the specified delimiter that matches the regular expression.

How can I convert comma separated string into a list string C#?

To convert a delimited string to a sequence of strings in C#, you can use the String. Split() method. Since the Split() method returns a string array, you can convert it into a List using the ToList() method.


1 Answers

If you don't want to use LINQ, you can do:

Dim foo As String = "a,b,c,d,e"
Dim boo As New List(Of String)(foo.Split(","c))
like image 59
Bob King Avatar answered Sep 21 '22 05:09

Bob King