0

我需要编辑变量中的字符串值。

所以,

00343755932

应转换为:

0,0,3,4,3,7,5,5,9,3,2

因为我必须将每个数字定义为一个变量数组,以便一个一个地读取。

4

1 回答 1

1

如果我是对的,您正在尝试从字符串创建一个数组。使用以下代码

String val = "00343755932";
        int[] numberArray = new int[val.length()];
        Matcher match = Pattern.compile("[0-9]").matcher(val);
        int i = 0;
        while(match.find()) {
            System.out.println(match.group());
            numberArray[i] = Integer.parseInt(match.group());
            i++;
        }
于 2015-06-13T23:08:40.320 回答