Java: Remove full stop in string

后端 未结 5 1474
死守一世寂寞
死守一世寂寞 2021-01-18 23:34

I want to delete all the full stops ( . ) in a string.

Therefore I tried: inpt = inpt.replaceAll(\".\", \"\");, but instead of deleting only the full st

5条回答
  •  天命终不由人
    2021-01-19 00:21

    String#replaceAll(String, String) takes a regex. The dot is a regex meta character that will match anything.

    Use

    inpt = inpt.replace(".", "");
    

    it will also replace every dot in your inpt, but treats the first parameter as a literal sequence, see JavaDoc.

    If you want to stick to regex, you have to escape the dot:

    inpt = inpt.replaceAll("\\.", "");
    

提交回复
热议问题