4

Display whitespace characters in Eclipse is a simple trick, but unfortunately this applies only on Editor views.

enter image description here

Is there a way to display these characters in the Console view too? I would find it useful for checking if strings are correctly formatted. Any help?

Community
  • 1
  • 1

2 Answers2

0

http://www.cafeaulait.org/course/week2/04.html

In short: You can use \r, \t, \f, and \n in the console text output for the needed whitespace. \t = Tab, \n = New line and etc. Check out the link for more details.

Gunnar
  • 2,255
  • 4
  • 18
  • 22
  • thank you, but isn't what i have asked :) please see edited question –  Jun 25 '12 at 16:02
0

As there was a bit of confusion regarding the term "whitespace characters", I will attempt to cover both possible instances.

If you wish to display such things as new lines and tabs, Java Strings include special characters for these constructs. \n will display a newline (line break). \t will display a tab. \r is a carriage return. There are others, as shown in the table here, but these are the most common.

Alternatively, if you intended displaying whitespace as a visible character, this is a different issue entirely. In this situation, I am assuming you wish to display a tab as an arrow or a space between words as a dot, like some text editors do. As far as I know, there is no built-in capability for this.

You could, however, replace existing whitespace with a unicode character that you want to represent that type of whitespace. The Java String class supports the use of unicode characters; it would just be a matter of finding the one you wish to use to indicate, say, a tab and then replacing all instances of \t with that symbol.

Roddy of the Frozen Peas
  • 11,100
  • 9
  • 37
  • 73
  • Yes, the second instance is the correct one :) maybe someone knows how to do it, or maybe already exist a Java function that replaces the characters... –  Jun 25 '12 at 16:39