Android Code Snippet Remove accents from string

Discussion in 'Code Snippets' started by Erel, Apr 29, 2014.

  1. Erel

    Erel Administrator Staff Member Licensed User

    SubName: RemoveAccents

    Description: Removes the accents and returns a new string

    Code:
    Sub Activity_Create(FirstTime As Boolean)
       
    Log(RemoveAccents("áóúñéí")) 'prints aounei
    End Sub

    Sub RemoveAccents(s As StringAs 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
    Tags: string accents

    Based on this link: http://stackoverflow.com/questions/5697171/regex-what-is-incombiningdiacriticalmarks
     
    arastoo, jmon, NeoTechni and 3 others like this.
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