Converting Accented Characters
Posted by Theo Heselmans on November 24th, 2007
Yesterday I needed a function to remove all accents from the accented characters in a string. I googled a bit, but did not find a clean solution. I needed it for Excel, but supposed it might be useful in Notes too.
So here's the function for 3 environments:
- for Excel and Lotusscript
Yes, they are the same (there are other solution too, certainly in Lotusscript, but I wanted to make is simple).Function StripAccent(thestring As String)
Dim A As String * 1
Dim B As String * 1
Dim i As Integer
Const AccChars= "ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðñòóôõöùúûüýÿ"
Const RegChars= "SZszYAAAAAACEEEEIIIIDNOOOOOUUUUYaaaaaaceeeeiiiidnooooouuuuyy"
For i = 1 To Len(AccChars)
A = Mid(AccChars, i, 1)
B = Mid(RegChars, i, 1)
thestring = Replace(thestring, A, B)
Next
StripAccent = thestring
End Function
- in Formula LanguageAccChars := @Explode("Š,Ž,š,ž,Ÿ,À,Á,Â,Ã,Ä,Å,Ç,È,É,Ê,Ë,Ì,Í,Î,Ï,Ð,Ñ,Ò,Ó,Ô,Õ,Ö,Ù,Ú,Û,Ü,Ý,"+
"à,á,â,ã,ä,å,ç,è,é,ê,ë,ì,í,î,ï,ð,ñ,ò,ó,ô,õ,ö,ù,ú,û,ü,ý,ÿ";",");
RegChars := @Explode("S,Z,s,z,Y,A,A,A,A,A,A,C,E,E,E,E,I,I,I,I,D,N,O,O,O,O,O,U,U,U,U,Y,"+
"a,a,a,a,a,a,c,e,e,e,e,i,i,i,i,d,n,o,o,o,o,o,u,u,u,u,y,y";",");
thestring:="Déjà nettoyé cette fenêtre?";
@Prompt([OK];thestring;@ReplaceSubstring(thestring;AccChars;RegChars));
Hope you can use it someday. Let me know.
Category: Domino/Notes Microsoft Excel | Technorati: Excel, Show-n-Tell Thursday, SnTT
Comments (4)
In LotusScript the Replace function works on arrays, too.
Thus, you could reduce your function to:
Function StripAccent(thestring As String)
Const ACC_CHARS = "Š,Ž,š,ž,Ÿ,À,Á,Â,Ã,Ä,Å,Ç,È,É,Ê,Ë,Ì,Í,Î,Ï,Ð,Ñ,Ò,Ó,Ô,Õ,Ö,Ù,Ú,Û,Ü,Ý,à,á,â,ã,ä,å,ç,è,é,ê,ë,ì,í,î,ï,ð,ñ,ò,ó,ô,õ,ö,ù,ú,û,ü,ý,ÿ"
Const REG_CHARS = "S,Z,s,z,Y,A,A,A,A,A,A,C,E,E,E,E,I,I,I,I,D,N,O,O,O,O,O,U,U,U,U,Y,a,a,a,a,a,a,c,e,e,e,e,i,i,i,i,d,n,o,o,o,o,o,u,u,u,u,y,y"
StripAccent = Replace(thestring, Split(ACC_CHARS, ","), Split(REG_CHARS, ","))
End Function
Theo, in formulas I use:
@Ascii("ŠŽšžŸÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðñòóôõöùúûüýÿ")
It works for all the accented characters in my language (Portuguese) but I think your language has a few more, you should try it anyway.
@Thomas
I knew, but wanted to make a 'general' function.
@Vitor
Great tip, never used @ASCII before.
@Thomas Bahn
Thanks a lot! Your function really helped me out!