Java replace all square brackets in a string

前端 未结 7 1157
执笔经年
执笔经年 2020-12-02 11:20

I want to remove square brackets from a string, but I don\'t know how.

String str = \"[Chrissman-@1]\";
str = replaceAll(\"\\\\[\\\\]\", \"\");

String[] tem         


        
7条回答
  •  自闭症患者
    2020-12-02 11:45

    The replaceAll method is attempting to match the String literal [] which does not exist within the String try replacing these items separately.

    String str = "[Chrissman-@1]";
    str = str.replaceAll("\\[", "").replaceAll("\\]","");
    

提交回复
热议问题