Android Question How to remove accents from text?

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code will remove the accents:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Log(RemoveAccents("áóúñéí"))
End Sub

Sub RemoveAccents(s As String) As String
   Dim normalizer As JavaObject
   normalizer.InitializeStatic("java.text.Normalizer")
   Dim n As String = normalizer.RunMethod("normalize", Array As Object(s, "NFD"))
   Dim sb As StringBuilder
   sb.Initialize
   For i = 0 To n.Length - 1
     If Regex.IsMatch("\p{InCombiningDiacriticalMarks}", n.CharAt(i)) = False  Then
       sb.Append(n.CharAt(i))
     End If
   Next
   Return sb.ToString
End Sub
 
Last edited:
Upvote 0
Top