Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emoji literal vs emoji unicode-escaped

Why there is a difference in how an emoji is displayed in JavaFX depending on if you're using a unicode escaping or not?

var button = new Button("Toggle Pane >\u2699< >⚙️<"); - in first pair of brackets a gear emoji will be placed, but in second pair - there will be a gear emoji and an empty rectangle.

If same Java string will be printed to console instead of being displayed in GUI, there will be no rectangle.

Screenshot of source and gui

Source .java file is UTF-8, you can paste emoji into text by pressing Win+; in Windows.

In Powershell there is also a difference:

"⚙️" | Format-Hex -Encoding utf32 | % HexBytes
# result: 99 26 00 00 0F FE 00 00
"`u{2699}" | Format-Hex -Encoding utf32 | % HexBytes
# result: 99 26 00 00

What's going on here?

like image 602
Podbrushkin Avatar asked Sep 20 '25 04:09

Podbrushkin


1 Answers

Invisible symbol after emoji is a variation selector.

Win+; pastes it into text after emoji. It is invisible character (selected on screenshot) which can be removed from source code after pasting emoji or stripped of by "⚙️".charAt(0).

In VSCode you can't select/delete this second char because caret treats this pair of chars as a whole, but in Notepad++ you can select this invisible char and delete it.

screenshot of source code and gui

What does u'\ufe0f' in an emoji mean? Is it the same if I delete it?

like image 71
Podbrushkin Avatar answered Sep 22 '25 16:09

Podbrushkin