9 Replies Latest reply on Aug 30, 2006 5:07 PM by Lukewig

    i want to know string contain symbol

    farhanakhan Level 1
      i wana to know that if string contain symbol then remove the symbol from string

      i dont know which type of symbol is in string find and remove the symbol and put spacce
      like this
      string is ================"screen-capturing"

      result will be screen capturing

      tell me the result
        • 1. Re: i want to know string contain symbol

          Not sure what you mean by "symbol" -- but if you mean that you want to remove any "non-word" characters from a string, then you can use a regular expression. If you have Director MX2004, create a new javascript member and paste this into it:

          function RegExp_Replace(str, repattern,rep,flags){
          // returns a new string
          return str.replace(RegExp(repattern,flags),rep);

          Now, to remove non-word characters (in Lingo), you would do this:

          str = "screen-capturing"
          str2 = RegExp_Replace(str "\W", " ","g")

          The pattern "\W" will match any "non-word character" (ie anything other than numbers, letters or underscore). If you also want to remove underscores, you could use this pattern:

          str2 = RegExp_Replace(str "[_\W]", " ","g")

          If you have an older version of Director, you can either use free PregEX Xtra (for Projectors) or do a basic character-by-character check in Lingo (which will be very slow for long strings)
          • 2. Re: i want to know string contain symbol
            Level 7
            I suspect that by symbol, he is referring to a symbol object, like the
            property name in a proplist. They must only contain alphanumeric
            characters or underscores, with no other characters. To simplify what
            Luke just wrote (I couldn't get his exact syntax to work, but this one
            worked for me), put this script into a JAVASCRIPT movie script.

            function cleanString(vText){
            return vText.replace(/[^0-9a-z]|"_"/gi," ");

            That will change any non-alphanumeric character to a space (including
            underscores). To use it, just call cleanString like this:

            put cleanString("screen-capturing")
            -- "screen capturing"

            As Luke had mentioned, this will only work with Dir MX2004 since you
            need to use javascript. If you have an older version, then you'll need
            to try a different route
            • 3. Re: i want to know string contain symbol
              farhanakhan Level 1
              thx a lot i need this but some differnet more i want programm automativally non-words characters from the string and put the space on it place
              but is also good i m using this
              • 4. Re: i want to know string contain symbol
                Hi Mike,
                Regarding your script, what will be the JavaScript syntax ??

                • 5. Re: i want to know string contain symbol
                  Level 7
                  I put the javascript syntax in my post:

                  function cleanString(vText){
                  return vText.replace(/[^0-9a-z]|"_"/gi," ");

                  If you mean the example where I used the Lingo put, you can use trace

                  -- "screen capturing"

                  Though that just puts the text in the Message Window. Normally you
                  would set a variable to the output of the function or use it to put text
                  into a Text member or something. I almost never use Javascript (except
                  in the instances like RegEx that there is no Lingo equivalent for), so I
                  may not be the best one to answer JS related issues...
                  • 6. Re: i want to know string contain symbol
                    AntiTRUST� Level 1
                    Wow Mike,
                    Its working perfect in Director, but unfortunately i have no help documents available in Director whcih can defines. I am also using Flash, i used the same script in flash with some alterations but not working in Flash.

                    But whatever, the script is really useful, wish to have the same script for our Flash(ActionScript).

                    Thanks a lot Mike and Luke and Farhana :)
                    • 7. Re: i want to know string contain symbol
                      farhanakhan Level 1
                      very nice
                      this code work perfectly
                      thx a lot

                      can u explain this function which u tell me i wana also know how it is work
                      the parameter which u pass i m confuse of it
                      i know it works fine but i wana also know how it is work

                      function cleanString(vText){
                      return vText.replace(/[^0-9a-z]|"_"/gi," ");
                      • 8. Re: i want to know string contain symbol
                        Level 7
                        It would take a lot longer time that I have to explain how regular
                        expressions work. And I only know the bare basics of them to begin
                        with. Basically a regular expression is a pattern matching algorithm.
                        You say what letters you want to find and what you want to do with those

                        function cleanString(vText){
                        return vText.replace(/[^0-9a-z]|"_"/gi," ");

                        In this example, the javascript replace function looks for the stuff in
                        the beginning between the / marks and replaces it with the " " (space).

                        The ^ character means "not" and everything in the brackets is what we
                        are not looking for. i.e. it is saying that anything that is not a
                        number (0-9) or a letter (a-z). Then the | pipe character means "or".
                        So in addition to the non alphanumerics, it is also looking for "_" the
                        underscore. Then after the last / are the switches. The g switch says
                        to match all of the instances of the pattern (without the g, it would
                        only replace the 1st one) and the i tells it to be case-insensitive..

                        Now are you more confused than before?

                        Here is a pretty good site with some more specific information about how
                        the replace method works in Javascript:


                        If you really want to get deep into regex, find the xtra for Director
                        called pRegEx. It is free and super powerful and superfast. The
                        documentation that comes with it is extremely detailed about all the
                        different functions of regular expressions and how to use them in Director.
                        • 9. Re: i want to know string contain symbol
                          Lukewig Level 1

                          I left off a comma (after the first parameter) in my email code - should have been: str2 = RegExp_Replace(str, "\W", " ","g")
                          The javascript should work though.

                          Incidentally, the main difference between



                          str.replace( repattern, rep )

                          is that in the former, a 'regular expression object" is created and given to the 'replace' method of the string object, rather than passing a literal regular expression. The advantage of the first way is that you can use Lingo strings to specify the regular expression (my 'RegExp_Replace' function is meant to be a general purpose wrapper for 'Replace' that can be called in Lingo). Using Mike's approach is certain better (and simpler) if you are happy to create the regular expression in Javascript.

                          -- Luke