在vb.net中将字符串转换为数组

时间:2011-03-11 18:54:19

标签: vb.net arrays

如何将字符串转换为数组?

值以字符串形式传递:

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

我的错误讯息是:Value of type 'String' cannot be converted to 'System.Array'

3 个答案:

答案 0 :(得分:13)

使用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)

或使用Microsoft.VisualBasic.Strings.Split:

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

答案 1 :(得分:3)

您可以使用split()。请参阅here

答案 2 :(得分:0)

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