[英]How to extract this string variable in android?
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]);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.