@Sphere Game Studio, I really don’t know why my code didn’t work with you…I tried on mac, windows, ipad mini and android device…all worked fine.
My approach was to see what emojis return code was. the ones I tried all had the same size (4 chars) and they all returned code 240 why I used string.byte to check their internal numerical codes. So I just had to compare a substring of 4 chars to check if they had that internal code. if they return that code you could change for whatever ou want. I used the “.” (dot)
my only concern was if there were emojis with different sizes. didn’t find one, and didn’t investigate further if there are or will be.
I’m glad you figured it out by yourself.
the code i used on devices to test was:
local defaultField local text=display.newText({text="",x=display.contentWidth\*.5, y=display.contentHeight\*.5+50, fontSize=14}) local text2=display.newText({text="",x=display.contentWidth\*.5, y=display.contentHeight\*.5+100, fontSize=14}) local function clean\_emoji(textIn) local text=textIn local i=1 while i\<=#text do local c = text:sub(i,i+3) if string.byte(c)==240 then text=string.gsub(text,c,".") text2.text=c end i=i+1 end return text end local function textListener( event ) if ( event.phase == "began" ) then elseif ( event.phase == "ended" or event.phase == "submitted" ) then elseif ( event.phase == "editing" ) then text.text=clean\_emoji(event.text) end end defaultField = native.newTextField( 150, 150, 180, 30 ) defaultField:addEventListener( "userInput", textListener )
I changed the “for” cicle for a “while” since usually “while” cicles are faster than “for” cicles…nothing more.