arrays - 将 string.Split (',' ) 转换为 int 数组

标签 arrays string actionscript-3 split

我有以下字符串:

“2,26,17,33,6,14,9,29,1”

还有一个int数组,usedIds

如果我这样做:

private var usedIds:Array;
usedIds = "2,26,17,33,6,14,9,29,1".split(',');

我得到一个字符串数组。

如何获取 int 数组?

最佳答案

最简单的方法是使用 Linq:

int[] usedIds = "2,26,17,33,6,14,9,29,1".split(',').Select(x => int.Parse(x)).ToArray();

关于arrays - 将 string.Split (',' ) 转换为 int 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6763056/

相关文章:

c++ - 如何制作一个包含一个字符 '-1' 的字符串?

xml - Flex 和嵌入式 XML

arrays - 如何从匿名Perl数组中获取所有从索引N到末尾的元素?

java - 在Java中是否可以导入数组类型?

javascript - 按每个对象数组中的值对对象数组进行排序

c++ - 将包含重音字符的 UTF-8 字符串转换为 UTF-16

c - C如何在printf语句中编译 "senthil"“kumar”?

flash - 为 Mac 和 PC 编译 Flash

actionscript-3 - AS3 停止外部 swf

php - 使用数组批量插入表