*
The moose likes Java in General and the fly likes Non-breaking space Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Non-breaking space" Watch "Non-breaking space" New topic
Author

Non-breaking space

Kowshik Nandagudi
Ranch Hand

Joined: Dec 09, 2010
Posts: 57
I came up with this issue.


output: B=         3+monthly(A,'mean')+3;C=B;'thisisacomment+3meansadding3

source.replaceAll("\\s",""); is replacing space with ascii value 32 and not non breaking space with ascii value 160.

I can replace it by checking for ascii value of each character and replace 32 and 160.

Is there any way I can replace any space using String functions

Thanks in advance
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

When it comes to printing to the console as you are doing there is no such character as a "non breaking space" and it is not normally needed since the console normally has a fixed width font and no interpretation is done that can in any way merge groups of spaces into just one space.

P.S. The ASCII characters have a range from 0x00 to 0x7e so 160 is not an ASCII character.


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Kowshik Nandagudi
Ranch Hand

Joined: Dec 09, 2010
Posts: 57
Thank you James.

I found this problem when my team member pasted the string "B = 3 + monthly(A,'mean')+3;C= B;'this is a comment +3 means adding 3" using a messenger. Found it strange in the beginning. and started printing the ascii value of each character using

It was printing 160 for the spaces after " = " character in the input string.

Verified the character for value 160 in Extended ASCII table and found it to be non breaking space.

Was just thinking this kind of scenarios can occur in real time .
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

I think I must be missing something. So all you are trying to do is replace the 160 chars with a space.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Non-breaking space
 
Similar Threads
Parse method discrepancy of NumberFormat(CurrencyFormatter)
Regular expression
regex Pattern class and spaces
ASCII value for Empty String.
How to remove spaces