Sub RemoveAccents (S As String) As String
Dim NaObj2 As NativeObject = S
NaObj2 = NaObj2.RunMethod("dataUsingEncoding:allowLossyConversion:",Array(1,True))
Dim NaObj As NativeObject
Return NaObj.Initialize("NSString").RunMethod("alloc",Null).RunMethod("initWithData:encoding:",Array(NaObj2,1)).AsString
End Sub
Sub RemoveAccents (S As String) As String
Dim NaObj2 As NativeObject = S
NaObj2 = NaObj2.RunMethod("dataUsingEncoding:allowLossyConversion:",Array(1,True))
Dim NaObj As NativeObject
Return NaObj.Initialize("NSString").RunMethod("alloc",Null).RunMethod("initWithData:encoding:",Array(NaObj2,1)).AsString
End Sub
Thanks! Your code works perfectly. Had done one manually which also works but your code is visually cleaner
B4X:
Sub IndexStr(Palavra As String, Posicao As Int) As String
Return Palavra.SubString2(Posicao, Posicao +1)
End Sub
Sub RemoverAcentos(Palavra As String) As String
Dim Acentos = "àâêôûãõáéíóúçüÀÂÊÔÛÃÕÁÉÍÓÚÇÜ"
Dim SemAcentos = "aaeouaoaeioucuAAEOUAOAEIOUCU"
Dim Posicao As Int
Dim Letra As String
Dim LetraSemAcento As String
For i = 0 To Palavra.Length-1'
Letra = IndexStr(Palavra, i)
Posicao = Acentos.IndexOf(Letra)
If Posicao > -1 Then
LetraSemAcento = IndexStr(SemAcentos,Posicao)
Palavra = Palavra.Replace(Letra, LetraSemAcento)
End If
Next'
Return Palavra
End Sub
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.