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
How can I do this?
I need this for my VB.NET project. Just the core concept will do
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
How can I do this?
I need this for my VB.NET project. Just the core concept will do
Use String.Split
and Int32.Parse
in this Linq query:
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:
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