Removing certain characters from a string

前端 未结 8 1463
清酒与你
清酒与你 2020-12-05 10:46

I am thinking about using String.replaceAll() to remove certain characters in my string. It is unclear which characters are going to be removed (i.e. which char

8条回答
  •  孤城傲影
    2020-12-05 11:36

    I think this can be done by using regular expressions.

    Firstly, we know [a-zA-Z]and $%! is valid for characters in string. So we use regx "[^a-zA-Z0-9$%!]" to strip out the other invalid chars. check http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html for detail info of JAVA patten.

    Next, we can usemystring.replaceAll(String regex, String replacement)

    P.S. RefexPlanet online Regular Expression Test Page

提交回复
热议问题