vb.net 如何拆分逗号分隔的字符串?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27035042/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:05:38 来源:igfitidea点击:
How do I split a comma separated string?
提问by Ozair Wani
I have a comma separated string.
我有一个逗号分隔的字符串。
e.g. {"one,two,three"}
Can anyone please tell me if I can create an array from this and if so, how? in VB.net.
任何人都可以告诉我是否可以从中创建一个数组,如果可以,如何创建?在 VB.net 中。
回答by Abbas Galiyakotwala
' 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
回答by Arion
Like this:
像这样:
dim str as string = "one,two,three"
dim str2() as string = split(str, ",")
Reference:
参考: