tnichol
tnichol

Reputation: 155

Underlining string in Groovy

How to write a string to a flat text file and specify underlining using Groovy or Java? Basically I'm converting a program from SQR to Groovy and SQR has this functionality but of course it uses a method that I do not have access to view so can't see how they're doing it. The SQR output looks odd but it works when printed and unfortunately I can't copy and paste it here but here's an image:

enter image description here

The words CODE and TRAN DESC get underlined when printed. I'm not sure what the whole BS thing is about other than it looks very much like a hard-coded carriage return character that I have used in previous programs.

Upvotes: 0

Views: 796

Answers (1)

cfrick
cfrick

Reputation: 37008

You would have to write the backspaces there simply in their unicode representation.

println "____\u0008\u0008\u0008\u0008CODE"

This would print four underscores, four backspaces, and the word.

If you have to do this alot, then a helper would help like this:

String underline(String text) {
    "_"*text.size() + "\u0008"*text.size() + text
}

assert underline("CODE")=="____\u0008\u0008\u0008\u0008CODE"

Upvotes: 2

Related Questions