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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5277118/
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-09 15:20:52  来源:igfitidea点击:

Converting a string to an Array in vb.net

vb.netarrays

提问by user279521

How can I convert a string into an array?

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

The values are passed as a string:

这些值作为字符串传递:

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

My error message is: Value of type 'String' cannot be converted to 'System.Array'

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

回答by Matt

Use System.String.Split:

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

Or use Microsoft.VisualBasic.Strings.Split:

或者使用Microsoft.VisualBasic.Strings.Split:

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

回答by decompiled

You can use split(). See here.

您可以使用 split()。见这里

回答by Zach Green

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

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