java如何将字符数组转换为int_将字符串数组转换为int数组

我会带着你远行 2022-11-03 16:22 428阅读 0赞

Dim stringList = {“123”, “456”, “789”}.ToList

Dim intList = stringList.ConvertAll(Function(str) Int32.Parse(str))

或与代表

Dim intList = stringList.ConvertAll(AddressOf Int32.Parse)

Dim stringArray = {“123”, “456”, “789”}

Dim intArray = Array.ConvertAll(stringArray, Function(str) Int32.Parse(str))

哦,我错过了样本数据中的空字符串 . 那你需要检查一下:

Dim value As Int32

Dim intArray = (From str In stringArray

Let isInt = Int32.TryParse(str, value)

Where isInt

Select Int32.Parse(str)).ToArray

顺便说一句,这里的方法语法相同,丑陋as always in VB.NET:

Dim intArray = Array.ConvertAll(stringArray,

Function(str) New With {

.IsInt = Int32.TryParse(str, value),

.Value = value

}).Where(Function(result) result.IsInt).

Select(Function(result) result.Value).ToArray

发表评论

表情:
评论列表 (有 0 条评论,428人围观)

还没有评论,来说两句吧...

相关阅读