Java 在输出文本中使用退格字符的替代方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18354749/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 00:50:23  来源:igfitidea点击:

Alternative to using backspace character in output text?

javaeclipse

提问by Ty De Salis

Is there is an alternative to the "\b" character, the backspace character, which deletes the text you just printed? It does not work in the Eclipse console.

是否有替代“\b”字符的退格字符,它会删除您刚刚打印的文本?它在 Eclipse 控制台中不起作用。

回答by Marko Topolnik

The Eclipse Console View is not a terminal emulator and doesn't even try to interpret any control codes besides the whitespace. Therefore the behavior isn't "buggy", it is like that by design.

Eclipse 控制台视图不是终端模拟器,甚至不会尝试解释除空格之外的任何控制代码。因此,行为不是“有问题的”,而是设计使然。

If you want to get control chars like \b(backspace) interpreted, your best bet is to run the Java program from the command line. Even in Windows' cmdit should work for \b.

如果您想获得\b解释(退格)之类的控制字符,最好的办法是从命令行运行 Java 程序。即使在 Windows 中,cmd它也应该适用于\b.

The \r(carriage return) character should also work for you on the command line. The advantage is that you need just one to get all the way back to the beginning of the line.

\r回车)字符也应该为你工作在命令行上。优点是您只需要一个就可以一直回到行的开头。

回答by misserandety

I agree with Marko, use different Compiler , or make a method for it instead

我同意 Marko,使用不同的 Compiler ,或者为它制作一个方法

    public static String b(String text){
    return text.substring(0,text.length()-1);
}

    System.out.println( b("This is my text") );

:P

:P