String operation fails with Emojis

I find myself in one of those excruciating almost there but not quite situations, where all the pieces of the puzzle are laid out and lined up, but one last item refuses to fall into place. Namely…

$myString = “Hello”
$myEmojis = “:smiley::smile::grin:
$myPointer = 1
$myChar = null

setVariable > Expression
myChar = mid($myString,$myPointer,1) // evaluates to “e” ◄ WORKS
myChar = mid($myEmojis,$myPointer,1) // evaluates to � ◄ FAILS

As you may have guessed, I was expecting :smile: in CASE 2. Is there something inherently ‘wrong’ about using Emojis in this manner?

NOTE I’m intentionally splitting this from a previous thread on using Emojis as icons.

Emoji are equivalent to two normal string ‘characters’, roughly speaking.

So you would need to make sure to start at the right position within the string (on the order of 2’s if everything is an emoji) and get a length of 2 normal ‘characters’ to properly render an emoji.


Very good to know! My initial plan involved simply listing the emojis in an array and using an index to select the one I want, which is how I’ve done it elsewhere. Once I achieve that level of proficiency with SharpTools, I’ll revisit that plan.

For now, thanks for the guidance!! (Promise I’ve been reading the Docs)

That’s certainly an option too.

Keep in mind that as of the writing of this post, there’s not currently an ‘array’ data type. Depending on your needs, the expression could hold the array if it’s static… or you could serialize and deserialize data into a text variable as alluded to in the other array thread you replied in.

1 Like