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种类型的字符串变量。 最佳答案
您可以拆分一个简单的正则表达式:
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]);
}
关于java - 如何在Android中提取此字符串变量?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17887708/