Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to strike any letter using Unicode in Java

Tags:

java

unicode

In my Java application I want to output striked letters (like html tag do). Is there any way to do this using Unicode (combine )

like image 558
vmg Avatar asked Aug 03 '11 14:08

vmg


People also ask

What is the Unicode for strikethrough?

To strikethrough a text or a symbol, type a letter and put a special hyphen next ̶. In Unicode this character is called «Combining Long Stroke Overlay». Done!

How do you write Unicode characters in Java?

Unicode character literals To print Unicode characters, enter the escape sequence “u”. Unicode sequences can be used everywhere in Java code. As long as it contains Unicode characters, it can be used as an identifier.

How do you strike through in Java?

You can add underline and strikethrough text using the Chunk class, and its setUnderline() method. You use a negative underline value to get the line lower below the text, and a positive underline value to get the line to strike through the text.


2 Answers

You can use U+0336, the combining long stroke overlay, to accomplish this task.

For comparison, here is what U+0336 looks like compared to html's <strike> tag:

U̶n̶i̶c̶o̶d̶e ̶c̶o̶m̶b̶i̶n̶i̶n̶g̶ ̶l̶o̶n̶g̶ ̶s̶t̶r̶o̶k̶e̶ ̶o̶v̶e̶r̶l̶a̶y̶
Hypertext strike tag

One thing to note though: If you look carefully at the "m" in "combining" above, you will probably see a small gap in the strike, due to the way combining overlay marks work. For this reason you should still prefer using html or some other technology over U+0336 for this purpose, if you have that option.

like image 63
AJMansfield Avatar answered Oct 02 '22 00:10

AJMansfield


No, this is not possible. While there is the concept of a stroke as diacritic, it's not available as a separate Unicode character, probably because the various letters that use a stroke diacritic do not place it at the same height or even angle. So the result would not resemble strikethrough markup anyway.

To output strikethrough text in Java, you need to use an output format that allows you to use explicit markup. If you have a Swing app, you're in luck as many Swing components support HTML. Otherwise it depends on what presentation technology you're using.

like image 28
Michael Borgwardt Avatar answered Oct 02 '22 00:10

Michael Borgwardt