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
?
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.
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.
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.
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.
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))
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