Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

%@LEN[emoji] is 1 but i want it to be 2 — is there something to do this?

Jul
534
10
How can I accurately measure the width of a string, if %@LEN[] returns 1 for double-wide characters?

I stumbled upon this “bug” when i noticed the code to wrap long lines on my bigecho.bat (echo but in double-height) was wrapping incorrectly.
1733855501588.webp

Notice the dropped "O" in Others.

The more emoji I put into the line, the worse it got:
1733855553700.webp


Eventually I realize, it was undercounting the emoji’s length, because it was counting it as one character, even though, at least visually, it’s length (width) is 2.

Is there some easy way around this?
 
Which emoji?

@LEN is the length of a string, not its width. @LEN counts many emojis as "two characters", but that's a happy coincidence at best. You could even call it a bug, just such a well-established bug that fixing it would be disastrous.
 
@LEN is calling a Windows API to get the string length, and technically Windows is correct - that emoji is one character.

What you're looking for is a function that returns the display width, not the character width. TCC & TCMD have an internal function that does that, but it is not exposed as a variable function (nobody has ever requested it before).

You could post it in the Suggestions Forum, or ask one of the plugin authors to whip up something for you.
 
Guess I’ll post it in the suggestions forum.

It’s just not possible to accurately align things otherwise, if emoji / double-width chars are involved.
 
Back
Top