如何拆分逗号分隔的字符串?

时间:2014-11-20 08:37:04

标签: vb.net

我有一个逗号分隔的字符串。

e.g. {"one,two,three"} 

任何人都可以告诉我,如果我可以从这个创建一个阵列,如果是这样,怎么样?在VB.net。

2 个答案:

答案 0 :(得分:14)

    ' you want to split this input string
    Dim s As String = "one,two,three"

    ' Split string based on comma
    Dim words As String() = s.Split(New Char() {","c})

    ' Use For Each loop over words and display them

    Dim word As String
    For Each word In words
        Console.WriteLine(word)
    Next

答案 1 :(得分:2)

像这样:

dim str as string = "one,two,three"
dim str2() as string = split(str, ",")

参考: