2

I have a string that would always output in the following format, but with different lengths.

String s1= "['Aaaa', 'Eeee', 'Ffff', 'Cccc', 'Dddd']";

How to split this string and store the values in a n array of strings, I tried String.Split(), but I failed to catch the inner values.

Do you think regular expressions could help???

4

3 回答 3

5

您是否尝试过Split使用正则表达式参数作为"[\\[\\]\\', ]"

基本上任何 [, ], ,, ', - 更多信息在这里

于 2012-12-13T08:07:46.830 回答
4

这是我的代码,希望它会有所帮助

    String s1 = "['Aaaa', 'Eeee', 'Ffff', 'Cccc', 'Dddd']";
    String s2 = "['Aaaa', 'Eeee']";
    String[] xx = s1.substring(2, s1.length() - 2).split("', '");
于 2012-12-13T08:11:14.177 回答
1
   String s1= "['Aaaa', 'Eeee', 'Ffff', 'Cccc', 'Dddd']";

       String[]  array = s1.split(",");
       for(int i=0;i<array.length;i++)
       {
           System.out.println(array[i]);
       }
于 2012-12-13T08:07:35.940 回答