3 Replies Latest reply on Feb 23, 2010 9:28 AM by archemedia

    Convert smart quotes

    SiHoop Level 1

      How can I replace smart quotes that have been entered into a form where the user has pasted from an MSWord document? I want to replace the smart quote with a simple apostrophe. I understand that the smart quote for a single quotation is represented by the following in Flex: ’

      Thank you!

        • 2. Re: Convert smart quotes
          SiHoop Level 1

          Perfect, thank you:

           

              for(var i:int=0; i<textAreaContent.text.length; i++){
                  //Convert all smart quotes to simple quotes. Use Unicode chars
                  //8216 is open single quote; 8217 is close single quote;
                  if(textAreaContent.text.charCodeAt(i)==8216||textAreaContent.text.charCodeAt(i)==8217){
                      textAreaContent.text=textAreaContent.text.substring(0, i)+"'"+textAreaContent.text.substring(i+1, textAreaContent.text.length)
                  }
                 
              }

          • 3. Re: Convert smart quotes
            archemedia Level 4

            If you use regular expressions, you could do it in a single line and much faster:

             

            In the following example, only the first instance of "sh" (case-sensitive)  is replaced:

             

             var myPattern:RegExp = /sh/
            var str:String = "She sells seashells by the seashore.";
            trace(str.replace(myPattern, "sch")); 
                // She sells seaschells by the seashore.

             

            In the following example, all instances of "sh" (case-sensitive)  are replaced because the g (global) flag is set in the regular expression:

             

             var myPattern:RegExp = /sh/g
            var str:String = "She sells seashells by the seashore.";
            trace(str.replace(myPattern, "sch")); 
                // She sells seaschells by the seaschore.

             

            Dany