String test=
["1","Low-level programming language",true],
["2","High level programming language",false],
["3","Machine language",false],["4","All of the above",false],
["5","None of these",false]我希望像[1","Low-level programming language",true]和其他文件一样将这个文件分成5种类型的字符串变量。
发布于 2013-07-26 17:49:03
您可以在一个简单的正则表达式中拆分:
String [] splitStrings = test.split("\\],\\[");您不希望只在逗号上拆分,因为您只想在方括号之间使用逗号。
下面是一个更完整的例子(如果您愿意的话,还有一个保持括号的正则表达式)
public static void main(String []args){
String test="[\"1\",\"Low-level programming language\",true],[\"2\",\"High level programming language\",false],[\"3\",\"Machine language\",false],[\"4\",\"All of the above\",false],[\"5\",\"None of these\",false]";
String [] splitStrings = test.split("(?!\\]),(?=\\[)");
System.out.println(splitStrings[0]);
System.out.println(splitStrings[1]);
System.out.println(splitStrings[2]);
System.out.println(splitStrings[3]);
System.out.println(splitStrings[4]);
}https://stackoverflow.com/questions/17887708
复制相似问题