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]
I want to separate this file like [1","Low-level programming language",true]
and others into 5 types of string variables.
You could split on a simple regex:
String [] splitStrings = test.split("\\],\\[");
You don't want to split on just comma because you only want the commas between the square brackets.
Here is a more complete example (and a regex that holds onto the brackets if you want)
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]);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.