How to extract this string variable in android?(如何在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中提取这个字符串变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在android中提取这个字符串变量?
基础教程推荐
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01
- 降序排序:Java Map 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01