Text to Emoji converter : v1.0

Yesterday I saw a tweet on my feed of a website that takes text and converts it emoji. Not all the words are converted (thank goodness!) but enough to create the right spacing for a classroom instruction to be a little more engaging. 

This got me thinking of how such a model could be written. So I thought of writing a small script that emulates a similar scenario. Since I spend a lot of time coding in Google Script these days, I thought of creating a similar, albeit limited, model. Here is what I have done so far. Hope this makes sense!

STEP 1 : The Data Source

As I mentioned I used Google Sheets for this. I have a Sheet document with two sheets in it. Sheet1 is where I input the text and translate it. Sheet2 is where the data source for the emojis is held. This data is sorted so that a binary search can be used later in the code.

Sheet 1
Sheet 2

STEP 2: The Code

The code comprises of two functions

  1. convertTexttoEmoji () : This is the main function that analyses the input text and outputs the converted emoji text.
  2. 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.

STEP 3: The Result

Now, once the code is set and relevant permissions granted to run, we test it.

Hurray! It works! I notice some spacing issues (hopefully v2.0 will fix it!) but apart from that message seems to have been converted pretty well.  


  • 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!
  • I am already working on a v2.0 so hope to blog that soon.