asales Expert Licensed User Longtime User Jun 18, 2019 #1 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.
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.
S sorex Expert Licensed User Longtime User Jun 18, 2019 #2 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 Upvote 0
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 B4X founder Staff member Licensed User Longtime User Jun 18, 2019 #3 It is not so simple because these characters are not contained in a single range. If you are only interested in ASCII characters: Code: Copy 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 Upvote 0
It is not so simple because these characters are not contained in a single range. If you are only interested in ASCII characters: Code: Copy 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 Expert Licensed User Longtime User Jun 25, 2019 #4 Thanks. Works fine. I just change the decimal number to 256 to include accents in the string. Code: Copy 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 Upvote 0
Thanks. Works fine. I just change the decimal number to 256 to include accents in the string. Code: Copy 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