DEV Community


Posted on • Updated on

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 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 ()


STEP 3: The result

Output 1

Output 2


  • 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!

Top comments (0)