GetDigits

By | 2012-10-13

Ever wanted to grab all the digits out of a string? This handy little function will do it. Not sure what purpose this would server, but someone requested it, so here it is.

For example, if you have a string value that contains “My n4me3 1s J0e”, this function will return a string value containing “4310”.

FUNCTION GetDigits(value)
   dim strOutput, strDigit, intKount
   strOutput = ""
   for intKount = 1 to Len(value)
      strDigit = Mid(value, intKount, 1)
      if (Asc(strDigit) >= Asc("0")) and (Asc(strDigit) <= Asc("9")) then
         strOutput = strOutput & strDigit
      end if
   next
   GetDigits = strOutput
END FUNCTION

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.