Copy link to clipboard
Copied
So I'm trying to remove the first character from a string if that character is a particular emoji. So far I have the code below which seems to work apart from the line 'name = name:sub(2)', which seems to just produce junk. Sorry for the screen grab, this page doesn't like emojis
Any thoughts, anyone?
Copy link to clipboard
Copied
[This post contains formatting and embedded images that don't appear in email. View the post in your Web browser.]
How LR handles Unicode strings in Lua isn't documented anywhere I know of (except on this forum).
Lua strings are sequences of 8-bit bytes, and Lua itself doesn't understand any Unicode encodings. If you write the following in a .lua source file and save the file encoded as UTF-8:
the source file contains four bytes between the open and close quotes. (The Unicode Red Textbook character is encoded in UTF-8 as four bytes.) Lua reads it as a four-byte string "\240\159\147\149". For example:
Lua doesn't provide any built-in operations for manipulating strings as sequences of Unicode characters, though there are open-source modules that provide UTF-8 operations on Lua strings.
LR generally treats Lua strings as containing UTF-8 encodings, so when LR displays a Lua string in its UI controls, it will interpret the string as UTF-8. (The screenshot above is from my debugging toolkit, which uses LrView controls.)
Finally, to remove the Unicode Red Texbook character from the beginning of a string, you could write:
Copy link to clipboard
Copied
And I just remembered my more concise post on this topic from 2010:
https://community.adobe.com/t5/lightroom-classic-discussions/how-the-sdk-handles-unicode/m-p/3072295
Copy link to clipboard
Copied
That did the job. Many thanks, John.