如何拆分包含两个保留字符的字符串

时间:2017-01-16 03:53:34

标签: java android arrays

如何拆分括号和花括号?

String items = [{person1=John Smith, person2=William Anderson}]

我已尝试过此代码String start = items.split("\\[\\{")[0];但这不起作用。

我想删除括号和花括号,所以我的输出应该是这样的,person1=John Smith, person2=William Anderson

2 个答案:

答案 0 :(得分:0)

你可以用它。

String []str=items.replace("[{","").replace("}]","").split(",");
        Log.e("first",str[0]);
        Log.e("second",str[1]);

答案 1 :(得分:0)

使用:

items = items.replace("\\[\\{", "").replace("\\}\\]", "");