4 Replies Latest reply on Jun 12, 2006 4:54 AM by Newsgroup_User

    How to extract numbers and characters from a string

    AntiTRUST�
      Hi Everyone,
      I need to know how can i extract numbers and characters from a variable/string ??

      For example;

      main_value = "YN012A7"

      into this one:

      main_characs = "YNA"
      main_nums = "127"



      Any help will be highly appreciated,
      Thanks in advance,
      Amir
        • 1. How to extract numbers and characters from a string
          SuperTank
          Not sure you've seen my reply on director-online´s forum. But here it goes.

          I havent tested this, but I do belive it should work.
          -----------------------------

          input_string = "YN012A7"
          char_part = ""
          int_part = ""

          repeat with i = 1 to input_string.length()

          tchar = input_string.Char[ i ]
          tvalue = value( tchar )

          if tvalue.ilk = #integer then
          int_part = int_part&tchar
          else
          char_part = char_part&tchar
          end if

          end repeat


          int_part = value( int_part )


          put "input_string:"&&input_string
          put "char_part:"&&char_part
          put "int_part:"&&int_part
          • 2. Re: How to extract numbers and characters from a string
            AntiTRUST� Level 1
            WOW
            SuperTank!
            Thank you soooooooo much for this help.

            I just removed the "()" from lenght and it worked. :)


            Thank you soo much,

            Regards,
            Amir
            • 3. Re: How to extract numbers and characters from a string
              Level 7
              parsedList = ParseNumbersAndAlphas ("498733h990h")
              numbers = parsedList [1]
              alphas = parsedList [2]

              on ParseNumbersAndAlphas str
              numChars = str.length
              numbers = ""
              alphas = ""
              numList = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57]
              repeat with x = 1 to numChars
              nextChar = str.char [x]
              asciiEquiv = nextChar.charToNum
              if numList.getOne (asciiEquiv) > 0 then -- it's a number
              numbers = numbers & nextChar
              else -- it's an alpha
              alphas = alphas & nextChar
              end if
              end repeat

              return [numbers, alphas]

              end

              I used a list to determine what characters would be flagged as numbers just
              to show that you could modify that list to parse any ascii values you want.
              Just add or delete ascii values from that list. If you wanted to parse just
              the letter "w" or "W" then numList would look like:

              [87, 119]

              --
              Craig Wollman
              Word of Mouth Productions

              phone 212 928 9581
              fax 212 928 9582
              159-00 Riverside Drive West #5H-70
              NY, NY 10032
              www.wordofmouthpros.com


              "AntiTRUST?" <webforumsuser@macromedia.com> wrote in message
              news:e6jk0l$kde$1@forums.macromedia.com...

              > Hi Everyone,
              > I need to know how can i extract numbers and characters from a
              > variable/string
              > ??
              >
              > For example;
              >
              > main_value = "YN012A7"
              >
              > into this one:
              >
              > main_characs = "YNA"
              > main_nums = "127"
              >
              >
              >
              > Any help will be highly appreciated,
              > Thanks in advance,
              > Amir
              >


              • 4. Re: How to extract numbers and characters from a string
                Level 7
                ...must not have been tested...


                --
                Craig Wollman
                Word of Mouth Productions

                phone 212 928 9581
                fax 212 928 9582
                159-00 Riverside Drive West #5H-70
                NY, NY 10032
                www.wordofmouthpros.com


                "AntiTRUST?" <webforumsuser@macromedia.com> wrote in message
                news:e6jkjf$l63$1@forums.macromedia.com...
                > WOW
                > SuperTank!
                > Thank you soooooooo much for this help.
                >
                > I just removed the "()" from lenght and it worked. :)
                >
                >
                > Thank you soo much,
                >
                > Regards,
                > Amir