Replace all occurrences of a character in a string in java?

Very noob question.

I want to replace all visibility. "" in a row with empty space ..

So this is what I tried

String s = "1.2.3.4"; System.out.println(s); s = s.replaceAll(".", " "); System.out.println(s); 

But the second seal is a blank font?

What did I miss here?

+6
source share
2 answers

You want to exit . . Otherwise, it can fit everyone.

Try s.replaceAll("\\.", " ") .

+9
source

Use String.replace (char, char) instead of String.replaceAll

+6
source

Source: https://habr.com/ru/post/956754/


All Articles