0

So I have been trying out different ways to represent information in the console and I have noticed printing \b doesn't remove newlines in the console.

Here is an example:

System.out.println("ggg");
System.out.print("\b\b\b\b\b\b\b\b\b\b\b\b");

shows up as ggg.

Is there a way to make this work?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83

2 Answers2

0

\b doesn't remove new lines, depending on the OutputStream, it may remove a character. For example, try

System.out.println("ggg\b");
Jason
  • 5,154
  • 2
  • 12
  • 22
0

"/b" just omit a character from the console; the problem is that in your code the "ggg" line will be printed and thew following "/b"s will be printed on a new line in the console, they can not affect the prior line. You need to use "/b" on the same line. Visit http://www.java2s.com/Code/Python/String/EscapeCodesbtnar.htm to grasp java escape codes.

iman rameshni
  • 34
  • 1
  • 4
  • thank you for clarifying, so to make sure I understand correctly, once the console moves on to the next line there is no way to go back to the previous line to change it. – brian dunne Mar 13 '20 at 22:53
  • exactly, as others mentioned \b can not remove characters from prior lines from console. once you printed something on the console you need to use console commands to manipulate it. – iman rameshni Mar 14 '20 at 11:51