Convert stored string of numbers to an array of integers

I have a comma string of numbers inside var named num_str

the contents of num_str look like this: "1,2,3,4,5", etc.

I'm looking for a way to add num_str to an expression to convert the number of numbers it contains into an array of integers

I want to make sure I can just refer to 'num_str' to get numbers instead of writing like {"1,2,3,4,5"}

I tried this where 'num_str' contains numbers

Dim test As String = Nothing
Dim result() As Integer = Int32.TryParse(num_str.Split(","c))
For i = 0 To result.Length - 1
   test += result(i)
Next

but it does not work

what I'm looking for is a result with an array of numbers

+4
source share
4 answers
Dim totalValue = str.
                 Split(","c).
                 Select(Function(n) Integer.Parse(n)).
                 Sum()
+11
source

Try creating an integer array

Dim numbers = str.Split(","c).[Select](Function(n) Integer.Parse(n)).ToList()

, ,

+2

:

Dim num_str As String = ...
Dim str() As String = num_str.Split(",")
Dim result(str.Length - 1) As Integer
For i = 0 To str.Length - 1
    result(i) = str(i)
Next
0

, , (, , "" ) " " . GPA, , GPA , - , .

For m = 0 To UBound(myArray)
myArray(m) = Replace(myArray(m), "thisstring", 0.0)  'integer 0.0 can be any
Next m
0

All Articles