简体   繁体   中英

How to print underlined string in console output in java

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

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[1m and \\033[0m (for bold ):

\033[1mInsert your String here\033[0m

You should read the documentation of your favorite console.

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

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

Also, this page may help

Notice I'm assuming you aim for bash like terminal

I used Netbeans IDE v12.0

String txt="Welcome Back";
String utxt = String.join("\u0332",n.split("",-1));
System.out.println(utxt);
Output
W̲e̲l̲c̲o̲m̲e̲ ̲B̲a̲c̲k̲

result in IDE

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM