StripNonNumeric Function using Regular Expressions by Ian Weatherburn

 

Contributed by
Rating:  stars stars stars stars stars / 0
October 03, 2000
Rate this Article:
MEH MEH++


SEARCH ASP FREE
TOOLS YOU CAN USE

advertisement

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
'*----------------------------------------------------------------------

blog comments powered by Disqus
ASP CODE ARTICLES

- ASP Forms
- ASP: The Beginning
- Getting Remote Files With ASP Continued
- Inbox and Outbox Manipulation in ASP
- Relational DropDownList Using VB.NET
- Ad Tracking URL Hits
- Use ViewState to display one record per page...
- Send Email using ASP.NET formatted in HTML
- ASP File Explorer
- ASP/XML Interview questions by Srivatsan Sri...
- Pressing RETURN won't submit the form
- This shows how you get the TEXT of a combo r...
- Group Data by Adrian Forbes
- Multiple checkbox select sample
- Multiple checkbox select with all values sam...

ASP Web Hosting ASP.Net Web Hosting Windows Web Hosting
 
 
 

ASP Free Forums 
 RSS  Tutorials RSS
 RSS  Forums RSS
 RSS  All Feeds
Site Map 
Request Media Kit
Write For Us Get Paid 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Privacy Policy 
Support 


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 5 - Follow our Sitemap
Most Popular Topics
All ASP.Net Tutorials