Xylex
Xylex

Reputation: 13

Remove Emoji from string in Lua

As the title states, I am trying to filter Emoji characters from input strings in Lua. This is for use within a telegram bot I have been working on. I have a command that will break if Emoji are passed into it.

'Hello World 😀'

to

'Hello world'

Upvotes: 0

Views: 549

Answers (1)

Piglet
Piglet

Reputation: 28984

In general I see three things you could do. You're currently asking how to solve 3.

  1. prevent emojis from being entered by ignoring anything you don't want to be entered

  2. if something you don't want has been entered, deny that input with an error message

  3. remove anything you don't want from the string befor you process it

To remove something from a Lua string you can simply replace it with an empty string. Use string.gsub and a pattern that matches all emojis.

I suggest you give this a read http://lua-users.org/wiki/LuaUnicode

Upvotes: 2

Related Questions