6

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'

3 Answers 3

17

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, ",")
Sign up to request clarification or add additional context in comments.

Comments

4

You can use split(). See here.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.