5

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?

4
  • What do you mean by 'whitespace characters'? Can you provide an example? Jun 25, 2012 at 15:48
  • If I understand correctly, @Roddy, OP wants whitespace displayed visibly in the console output. Jun 25, 2012 at 15:50
  • @DanielFischer - I was curious whether the OP intended whitespace like \t, etc, or like some text-editors provide where a ␣ or dot represent a single space and a right arrow represents a tab. Jun 25, 2012 at 15:51
  • @Roddy If I guess correctly, either will do, since both allow to check the formatting. But of course I might guess wrong. Jun 25, 2012 at 15:54

2 Answers 2

1

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.

1
  • 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...
    – user1266094
    Jun 25, 2012 at 16:39
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.

1
  • thank you, but isn't what i have asked :) please see edited question
    – user1266094
    Jun 25, 2012 at 16:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.