Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting a string to an Array in vb.net

Tags:

arrays

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'

like image 608
user279521 Avatar asked Dec 01 '22 08:12

user279521


2 Answers

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, ",")
like image 143
Matt Avatar answered Dec 06 '22 09:12

Matt


You can use split(). See here.

like image 32
decompiled Avatar answered Dec 06 '22 09:12

decompiled