DEV Community

Shashi
Shashi

Posted on • Edited on

2 1

Text to Emoji converter using G-Script

Did something I found fun. So sharing it here. If there are teachers on here they can think of ways to use this as a model to teach different coding concepts to students.

I designed a small Google script code that accepts plain text and converts it into Emoji text. Basic steps below.

STEP 1: Setting up the Google sheet.

I have 2 sheets. One for the inputs/generated output and another for the lookup which has the word > equivalent emoji. This second sheet is sorted by word so that Binary Search can be implemented for the search.

SHEET 1
Sheet 1

SHEET 2
Sheet 2

STEP 2: The code

The code comprises of two functions.

convertTexttoEmoji () : This is the main function that analyses the input text and outputs the converted emoji text.
getEmoji() : This function is called by convertTexttoEmoji() and does the heavy work of looking up matching emoji icons for every word. This is the function which uses a Binary Search for this operation.

convertTexttoEmoji ()
convertTexttoEmoji

getEmoji()
getEmoji()

STEP 3: The result

Output 1

Output 2

CONCLUSIONS:

  • The words being looked at are absolute matches (including case-sensitivity). So if I were to type "bike" instead of "biking" it will not work. Solution? Add more words to the data set with a comma and do a second level look up for similar words + force lower case on them for consistency check.

  • Splitting this text into an array was easy but handling punctuation in the output was a little tricky due to the spaces.

  • The emoji database itself is limited so a much larger data set might take longer to run/execute.

  • Emojis look different on different devices. So a mountain may look perfect on your device and may look like a big ugly triangle on some other device. Testing it with various devices is a good idea!

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay