3 Replies Latest reply on Dec 14, 2007 9:01 AM by exPluda?

    removing accents


      I need some help manipulating a string to remove all possible accents to avoid server problems.

      I have per example this "áçõê" and I need to have "acoe", but the string can also be "éàç", so I can't use the split("á"). I need to have a global function who can deal with all the accents at once.

      Any sugestion?

        • 1. Re: removing accents
          exPluda? Level 1
          trying like this I got no result, I think inside a loop flash can't replace all at once.

          how should I change this code?


          var o_que:String = "TESTÈ de AÇçentos à é ì í ó ã";
          var lowercase:String = o_que.toLowerCase();
          var sem_espacos:String = lowercase.split(" ").join("_");
          var sem_pontos:String = sem_espacos.split(".").join("");
          var acentos:Array = new Array("á","à","é","è","í","ì","ó","ò","ö","ő","ú","ù","ü","ű","ç");
          var substituir:Array = new Array("a","a","e","e","i","i","o","o","o","o","u","u","u","u","c");
          for (as=0; as<acentos.length; as++) {
          var o_que_corrigido:String = sem_pontos.split(acentos[as]).join(substituir[as]);
          • 2. removing accents
            BSpero Level 1
            Your code is actually ALMOST correct. Use "sem_pontos" in the repeat loop and trace that out, it should work. You keep resetting the variable over and over, while never manipulating the modified results. Just change the line:

            • 3. Re: removing accents
              exPluda? Level 1
              Hello BSpero, thanks for reply

              yep, you're right, it works now

              Many thanks man :-)