Replace period with white space

I am trying to replace a period in a string with a white space. It does not want to work with a period but works just fine with a comma!

Please can somebody tell me what I am doing wrong.

This is the code that I am using:

System.out.println("Unicode:" +"\u002E");

CharSequence inputStr ="12.345,67";

String patternStr ="\u002E";

String replacementStr =" ";

//Compile regular expression

Pattern pattern = Pattern.compile(patternStr);

//Replace all occurrences of pattern in input

Matcher matcher = pattern.matcher(inputStr);

String output = matcher.replaceAll(replacementStr);

System.out.println("output:" + output);

[918 byte] By [leofoxa] at [2007-10-3 3:02:10]
# 1
The dot is a special character in regular expressions. Escape it with \\.
Herko_ter_Horsta at 2007-7-14 20:51:54 > top of Java-index,Java Essentials,New To Java...
# 2
Since you're only replacing one character with another use String.replace():replacementStr = inputStr.replace('.',' ');
killerCodingNinjaMonkeya at 2007-7-14 20:51:54 > top of Java-index,Java Essentials,New To Java...
# 3

As mentioned "." is considered differently in regular expressions. You can change the patterStr

to "[.]"

and your code will work.

Since you have used replaceAll()

I guess as the size of inputStr varies many thousand seperator can occur. Even then the fix mentioned by me will work

Thanks

Arun

The_Ghost_Who_Walksa at 2007-7-14 20:51:54 > top of Java-index,Java Essentials,New To Java...