如何在java的控制台输出中打印带下划线的字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19354875/
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 16:24:31  来源:igfitidea点击:

How to print underlined string in console output in java

javastring

提问by Harshal

I want to know if there is any way to print the underlined text on console using java String class.

我想知道是否有任何方法可以使用 java String 类在控制台上打印带下划线的文本。

采纳答案by Arnaud Denoyelle

You can only rely on how the String is interpreted by your console. For example, in bash, you can do something like inserting your string between escape sequences \033[1mand \033[0m(for bold):

您只能依赖控制台如何解释字符串。例如,在 中bash,您可以执行一些操作,例如在转义序列\033[1m\033[0m(对于bold)之间插入字符串:

3[1mInsert your String here3[0m

You should read the documentation of your favorite console.

您应该阅读您最喜欢的控制台的文档。

回答by David Rabinowitz

I'd have a look at the tputcommand as outlined in this answer, but it will make your code a bit unreadable as it will look like this

我会看看这个答案中tput概述的命令,但它会让你的代码有点不可读,因为它看起来像这样

System.out.println("...")
// execute tput
System.out.println("underlined text")
// execute tput
System.out.println("...")

Also, this pagemay help

此外,此页面可能会有所帮助

Notice I'm assuming you aim for bash like terminal

注意我假设你的目标是像终端一样的 bash

回答by Harish Kumar

On my IDE you can also use like the below Mentioned :

在我的 IDE 上,您也可以像下面提到的那样使用:

System.out.println("Underlined Text");
System.out.println("_______________")