Skip to main content
Inspiring
February 16, 2024
Question

Tring to remove first character from a string if it's a particular emoji

  • February 16, 2024
  • 1 reply
  • 451 views

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? 

 

 

 

 

 

This topic has been closed for replies.

1 reply

johnrellis
Legend
February 16, 2024

[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:

 

 

 

 

johnrellis
Legend
February 16, 2024

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