[英]Splitting a string of characters in vb.net
I need to split a string like the one show below 我需要拆分一个字符串,就像下面的一个节目一样
13,14,15,16,17
into 成
13 14 15 16 17
and store them in an integer array 13 14 15 16 17
并将它们存储在整数数组中
How can I do this? 我怎样才能做到这一点?
I need this for my VB.NET project. 我需要这个用于我的VB.NET项目。 Just the core concept will do 只有核心概念才能做到
Use String.Split
and Int32.Parse
in this Linq query: 在此Linq查询中使用String.Split
和Int32.Parse
:
Dim intArr = str.Split(","c).Select(Function(s) Int32.Parse(s)).ToArray()
or, if you find the query-syntax easier: 或者,如果您发现查询语法更容易:
Dim ints = From str In str.Split(","c)
Select Int32.Parse(str)
dim intArr = ints.ToArray()
here the old approach without Linq but correctly sized array: 这里没有Linq但是正确大小的数组的旧方法:
Dim strArr = str.Split(","c)
Dim intArr(strArr.Length - 1) As Int32
For i As Int32 = 0 To strArr.Length - 1
intArr(i) = Int32.Parse(strArr(i))
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.