【问题标题】:Converting a string to an Array in vb.net在 vb.net 中将字符串转换为数组
【发布时间】:2011-03-11 18:54:19
【问题描述】:

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

值作为字符串传递:

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

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

【问题讨论】:

    标签: vb.net arrays


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      你可以使用 split()。见here

      【讨论】:

        【解决方案3】:

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-12-12
          • 2021-08-26
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多