Java 如何使用两个保留字符拆分字符串
如何拆分括号和花括号Java 如何使用两个保留字符拆分字符串,java,android,arrays,Java,Android,Arrays,如何拆分括号和花括号 String items = [{person1=John Smith, person2=William Anderson}] 我已经尝试过这个代码String start=items.split(“\\[\\{”)[0];,但这不起作用 我想去掉括号和花括号,所以我的输出应该是这样的,person1=John Smith,person2=William Anderson您可以使用它 String []str=items.replace("[{","").replace(
String items = [{person1=John Smith, person2=William Anderson}]
我已经尝试过这个代码String start=items.split(“\\[\\{”)[0];
,但这不起作用
我想去掉括号和花括号,所以我的输出应该是这样的,person1=John Smith,person2=William Anderson
您可以使用它
String []str=items.replace("[{","").replace("}]","").split(",");
Log.e("first",str[0]);
Log.e("second",str[1]);
使用:
请举例说明您想要的输出,因为您的问题不清楚。您所说的“分割括号和花括号”是什么意思?您期望的结果是什么?您想要什么值作为输出???请具体说明。对不起,我已经编辑了我的问题。@davidchowellery您需要
#String.replaceAll()
而不是#String.split()
items = items.replace("\\[\\{", "").replace("\\}\\]", "");