如何将字符串转换为数组?
值以字符串形式传递:
Dim strInput as string
strInput = "Tom, John, Jason, Mike"
我的错误讯息是:Value of type 'String' cannot be converted to 'System.Array'
答案 0 :(得分:13)
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)