本文介紹了如何在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種字符串變量.
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]);
}
這篇關于如何在android中提取這個字符串變量?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!