user279521
user279521

Reputation: 4807

Converting a string to an Array in vb.net

How can I convert a string into an array?

The values are passed as a string:

Dim strInput as string  
strInput = "Tom, John, Jason, Mike"  

My error message is: Value of type 'String' cannot be converted to 'System.Array'

Upvotes: 6

Views: 55650

Answers (3)

Matt
Matt

Reputation: 14531

Use System.String.Split:

Dim source As String = "Tom, John, Jason, Mike"
Dim stringSeparators() As String = {","}
Dim result() As String
result = source.Split(stringSeparators, _ 
                      StringSplitOptions.RemoveEmptyEntries)

Or use Microsoft.VisualBasic.Strings.Split:

Dim source As String  = "Tom, John, Jason, Mike"
Dim result() As String = Split(source, ",")

Upvotes: 17

Zach Green
Zach Green

Reputation: 3460

strInput.Split(New String() {", "}, StringSplitOptions.RemoveEmptyEntries)

Upvotes: 2

decompiled
decompiled

Reputation: 1921

You can use split(). See here.

Upvotes: 4

Related Questions