Android Question [Solved] How do remove emoticons characters from a string?

sorex

Expert
Licensed User
it depends on how they are added. if they all use something like [smile] or :smile: it's easy.

if it is a mix of things you probably need to use a loop with replacement parameters to use with regex.replace
 

Erel

Administrator
Staff member
Licensed User
It is not so simple because these characters are not contained in a single range.

If you are only interested in ASCII characters:
B4X:
Dim sb As StringBuilder
sb.Initialize
For i = 0 to s.Length - 1
 Dim c As String = s.CharAt(i)
 If Asc(c) < 128 Then sb.Append(c)
Next
Return sb.ToString
 

asales

Well-Known Member
Licensed User
Thanks. Works fine.
I just change the decimal number to 256 to include accents in the string.

B4X:
Sub RemoveEmojis(s As String) As String
    Dim sb As StringBuilder
    sb.Initialize
    For i = 0 To s.Length - 1
        Dim c As String = s.CharAt(i)
        If Asc(c) < 256 Then sb.Append(c)
    Next
    Return sb.ToString
End Sub
 
Top