Announcement

Collapse
No announcement yet.

Find a number in a string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Find a number in a string

    Hi, how can I return the index of the number substring in alphanumeric strings?
    Ex:
    hello145hello
    I need to return the start and the end position of 145

    Bye

  • #2
    Re: Find a number in a string

    Do you know before hand what the numbers are? Or are you wanting something like an IsNumeric to tell if its alpha or numeric, and then start counting until an alpha is found again?

    Comment


    • #3
      Re: Find a number in a string

      No, I don't know what's the number in the string. I need to read a random string and return only the numeric value in the string.
      Ex2: HE34590LLO
      Numeric Value: 34590

      Comment


      • #4
        Re: Find a number in a string

        I don't know of an easy way but you could try something like this.

        Get the complete string.
        Get the total length of the string

        Get the first character of the string
        If it is >= 0 keep it and check the next character
        Else get the total string minus the first character

        REPEAT until you checked the entire string for digits.

        Comment


        • #5
          Re: Find a number in a string

          Try this:

          <pre>
          %TestString% = "HE34590LLO"
          %Length% = String.GetLength ("%TestString%")
          %Ctr% = "0"
          %HIT% = "FALSE"

          WHILE (%Ctr% < %Length%)
          %SubString% = String.Mid ("%TestString%", %ctr%, 1)
          %IsZero% = Evaluate (%Substring% * 0)
          IF (%IsZero% = 0)
          IF (%HIT% = "FALSE")
          %FirstDigit% = "%Ctr%"
          %HIT% = "TRUE"
          END IF
          ELSE
          IF (%HIT%="TRUE")
          %LastDigit% = Evaluate (%Ctr%)
          %NumberOfDigits% = Evaluate (%LastDigit% - %FirstDigit%)
          %NumericValue% = String.Mid ("%TestString%", % FirstDigit%, %NumberOfDigits%)
          %Result% = Dialog.MessageBox ("Title", "The numeric value in the strin...", Ok, Question)
          %Ctr% = "%Length%"
          END IF
          END IF
          %Ctr% = Evaluate (%Ctr% + 1)
          END WHILE</pre>

          Cut and Paste Version Here

          Comment


          • #6
            Re: Find a number in a string

            ok thx! [img]/ubbthreads/images/icons/smile.gif[/img]

            Comment

            Working...
            X