将保存的数字字符串转换为整数数组 [英] convert saved string of numbers into an array of integers
本文介绍了将保存的数字字符串转换为整数数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在名为num_str的变量中,我有一个逗号分隔的数字字符串。
i have a comma separated string of numbers inside of a var named num_str
num_str的内容如下: 1,2,3,4,5 etc
the contents of num_str looks like this: "1,2,3,4,5" etc
我正在寻找一种将num_str添加到表达式中以将其中包含的数字形式转换为整数数组的方法
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
我想确保我可以简单地引用'num_str'来获取数字,而不是像{ 1,2,3,4,5}那样拼写出来
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"}
我已经尝试过,其中'num_str'包含数字
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
但这不起作用
我要查找的是带有数字数组的结果
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()
这篇关于将保存的数字字符串转换为整数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文