vb.net 如何根据VB.Net中的分隔符将字符串拆分为数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9078031/
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
How to split a string into array based on delimitter in VB.Net
提问by Santhosh_ms3
How can I assign a split parts of a string into an array list directly ?
如何将字符串的拆分部分直接分配到数组列表中?
String format:
字符串格式:
ABC;PQR;XYZ
ABC;PQR;XYZ
回答by Konrad Rudolph
Not sure what you want but doesn't the following serve your purpose?
不确定您想要什么,但以下内容不符合您的目的吗?
Dim input As String = "ABC;PQR;XYZ"
Dim x As New List(Of String)(input.Split(";"c))
Notice that I've used the superior List<String>
(from System.Collections.Generic
) instead of the deprecated ArrayList
.
请注意,我使用了上级List<String>
(from System.Collections.Generic
) 而不是已弃用的ArrayList
.
Also, do you really need a modifiable List
? Unless you want to add or remove entries, a plain array should be fine.
另外,你真的需要一个可修改的List
吗?除非您想添加或删除条目,否则普通数组应该没问题。
回答by LordDraagon
Const XHundred = ",C,CC,CCC,CD,D,DC,DCC,DCCC,CM"
Const Xten = ",X,XX,XXX,XL,L,LX,LXX,LXXX,XC"
Const Xone= ",I,II,III,IV,V,VI,VII,VIII,IX"
I used this in a function. then later at the end of the function I used split() to split these into string arrays.
我在一个函数中使用了它。然后在函数的末尾我使用 split() 将它们拆分为字符串数组。