Question
· Dec 2, 2016

How to remove accentuation?

How to remove accentuation of a word?

Ex:

Árvore = Arvore

você = voce

Então = entao

The words above are in brazilian portuguese, I need to get rid with the accentuation such that I can compare two sentences.

Thanks in advance.

Discussion (5)3
Log in or sign up to continue

Another option is to use a regular expression, like this:

ClassMethod ReplaceAccents(ByRef pWord As %String) As %Status
{
  Set tSC = $$$OK
  Try {
      Set dictionary = ##class(%ArrayOfDataTypes).%New()
      Do dictionary.SetAt("ÀÁÂÃÄÅ","A")
      Do dictionary.SetAt("àáâãäå","a")
      Do dictionary.SetAt("ÈÉÊË","E")
      //.... all the rest
   
      While dictionary.GetNext(.key) {
        Set matcher = ##class(%Regex.Matcher).%New("["_ dictionary.GetAt(key) _ "]", pWord)
        Set pWord = matcher.ReplaceAll(key)
      }
  Catch tException {
    Set:$$$ISOK(tSC) tSC = tException.AsStatus()
  }
  Quit tSC
}