replace special characters in string in java

前端 未结 4 469
没有蜡笔的小新
没有蜡笔的小新 2020-12-02 02:22

I want to know how to replace the string in Java.

E.g.

String a = \"adf�sdf\";

How can I replace and avoid special characters?

4条回答
  •  日久生厌
    2020-12-02 02:33

    Assuming, that you want to remove all special characters, you can use the character class \p{Cntrl} Then you only need to use the following code:

    stringWithSpecialCharcters.replaceAll("\\p{Cntrl}", replacement);
    

提交回复
热议问题