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

Discussion in 'Android Questions' started by asales, Jun 18, 2019.

  1. asales

    asales Well-Known Member Licensed User

    I see the code to remove accents from a string
    https://www.b4x.com/android/forum/threads/remove-accents-from-string.40429/#content

    I have strings with emoticons, like this example:
    Have fun!!✌️Good luck!❤️✝️Happy birthday!✝️Do you want a beer??☀️☀️Have a nice day! Give my money$$!!✝️

    Is possible to remove all the emoticons (✌️❤️☀️✝️ and others) from the string and left only the texts?

    Thanks in advance for any tip.
     
  2. sorex

    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
     
    asales likes this.
  3. Erel

    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:
    Code:
    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 likes this.
  4. asales

    asales Well-Known Member Licensed User

    Thanks. Works fine.
    I just change the decimal number to 256 to include accents in the string.

    Code:
    Sub RemoveEmojis(s As StringAs 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
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice