5 Replies Latest reply on Jul 4, 2006 12:01 AM by AntiTRUST�

    How to extract sub string value from a string?

    AntiTRUST�
      Hi,
      I need to know how can i extract sub strings from a main string, something like this:

      main variable-------->"2087-5E2SE-19-JG7BC"

      i want to split it into like this:

      sub_main_1 variable---------> "2087"
      sub_main_2 variable---------> "5E2SE"
      sub_main_2 variable---------> "19"
      sub_main_2 variable---------> "JG7BC"


      I did the same in flash by using Split and arrays, like this:

      var my_str:String = "2087-5E2SE-19-JG7BC";
      var my_array:Array = my_str.split("-");
      for (var i = 0; i<my_array.length; i++) {
      trace(my_array );
      }

      this.aaa1 = my_array[1];
      this.aaa2 = my_array[2];
      this.aaa3 = my_array[3];
      this.aaa4 = my_array[4];





      My question is that how can i do the same in director ?? i haven't find any split function in director.

      Thanks in advance,
      Amir
        • 1. Re: How to extract sub string value from a string?
          Level 7
          You do a similar thing in Director using the itemDelimiter, which is a
          _player object property in MX2004. By default, it's a comma:

          put _player.itemDelimiter
          -- ","

          It will let you get specific items within a string.

          p = "2087-5E2SE-19-JG7BC"
          _player.itemDelimiter = "-"
          put p.item[1]
          -- "2087"

          You could use it to write yourself a little split function:

          on split(theString, theDelimiter)
          oldDelim = _player.itemDelimiter
          _player.itemDelimiter = theDelimiter
          itemList = []
          repeat with cnt = 1 to theString.item.count
          itemList.add(theString.item[cnt])
          end repeat
          return itemList
          end


          p = "2087-5E2SE-19-JG7BC"
          a = split(p, "-")
          put a
          -- ["2087", "5E2SE", "19", "JG7BC"]


          --
          Dave -
          Adobe Community Expert
          www.blurredistinction.com
          http://www.adobe.com/communities/experts/


          • 2. Re: How to extract sub string value from a string?
            Level 7
            AntiTRUST? wrote:
            > Hi,
            > I need to know how can i extract sub strings from a main string,
            > something like this:
            >
            > main variable-------->"2087-5E2SE-19-JG7BC"
            >
            > i want to split it into like this:
            >
            > sub_main_1 variable---------> "2087"
            > sub_main_2 variable---------> "5E2SE"
            > sub_main_2 variable---------> "19"
            > sub_main_2 variable---------> "JG7BC"
            >


            on test
            tid=the itemDelimiter -- save it
            the itemdelimiter="-"
            str="2087-5E2SE-19-JG7BC"
            itum=[]
            n=str.item.count
            repeat with i=1 to n
            add itum, str.item
            end repeat
            put itum
            the itemDelimiter=tid -- restore
            end test

            -- Welcome to Director --
            test
            -- ["2087", "5E2SE", "19", "JG7BC"]

            Andrew


            • 3. Re: How to extract sub string value from a string?
              Level 7
              I forgot to add the line to set the itemDelimiter back to it's original
              value when the function is complete. It's not something I regularly do, but
              it's considered good form to do it.

              on split(theString, theDelimiter)
              oldDelim = _player.itemDelimiter
              _player.itemDelimiter = theDelimiter
              itemList = []
              repeat with cnt = 1 to theString.item.count
              itemList.add(theString.item[cnt])
              end repeat
              _player.itemDelimiter = oldDelim
              return itemList
              end



              --
              Dave -
              Adobe Community Expert
              www.blurredistinction.com
              http://www.adobe.com/communities/experts/


              • 4. Re: How to extract sub string value from a string?
                Minds Eye Level 1
                Another way you can do it is to use our FREE Xtra "Minds Eye String Handler"
                You can download it from
                http://www.the-mindseye.co.uk/prog/string_handler.shtml

                It contains loads of string handling functions including functions that place delimited strings into a list:

                str = "2087-5E2SE-19-JG7BC"

                --create an instance of the Xtra
                p_oString=new(xtra "mevString", str)
                --set the delimiter to "-"
                p_oString.mevcFieldSetDelim(charToNum("-"))

                --dump out the list
                put p_oString.mevcFieldList()
                -- ["2087", "5E2SE", "19", "JG7BC"]
                • 5. Re: How to extract sub string value from a string?
                  AntiTRUST� Level 1
                  Hi all,
                  Thanks a lot, and thanks a million!
                  Its all done, i never heard of this itemDelimiter, its really very useful.

                  Thanks a lot guys. :)