i have a comma separated string of numbers inside of a var named num_str
the contents of num_str looks like this: "1,2,3,4,5" etc
i am looking for a way to add num_str to an expression to convert the sting of numbers contained therein to an array of integers
i want to make sure i can simply reference 'num_str' to get the numbers from instead of spelling it out like {"1,2,3,4,5"}
i have tried this, where 'num_str' contains the 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 that doesn't work
what i am looking for is a result with an array of numbers
Dim totalValue = str.
Split(","c).
Select(Function(n) Integer.Parse(n)).
Sum()
Try this to create integer array
Dim numbers = str.Split(","c).[Select](Function(n) Integer.Parse(n)).ToList()
Then you can use the loop you are using at the moment to append value to string
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With