StripNonNumeric Function using Regular Expressions by Ian Weatherburn
I attach a revised version (written in VB, but easily converted to VBScript) that uses regular-expression matching to perform a far more efficient replacement. On a 440,754 byte file your routine took about 14 seconds while on the same file the regular expression matching took less than 1 second!!!!
Kind Regards
Ian Weatherburn
Here is the attached regular expression algorithm.
'*---------------------------------------------------------------------- '* Method: StripNonNumeric '* Parameters: sInput - The string to remove numeric values from '* sReplaceStr - (Optional) Replace values with this string '* Defaults to empty string ("") '* Returns: String - The replace string '* Description: Utilising regular expression matching, remove numeric '* values from the passed string and return the cleaned '* up string '*---------------------------------------------------------------------- Private Function StripNonNumeric(ByVal sInput As String, _ Optional ByVal sReplaceStr As String = "") As String Dim objRegExp As Object Dim sNew As String
' Create an instance of the VBScript Regular Expression matching object Set objRegExp = CreateObject("VBScript.RegExp")
With objRegExp ' A Boolean value that indicates if a pattern should match all occurrences ' in an entire search string or just the first one. .Global = True
' Sets or returns a Boolean value that indicates if a pattern search is ' case-sensitive or not. Redundant in this case - for example only .IgnoreCase = True
' Sets or returns the regular expression pattern being searched for .Pattern = "[0123456789]"
' Replaces text found in a regular expression search. sNew = .Replace(sInput, sReplaceStr)
End With ' objRegExp
' Release the regular expression matching object Set objRegExp = Nothing
' Return the stripped string StripNonNumeric = sNew End Function ' StripNonNumeric '*----------------------------------------------------------------------