Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 7th, 2007, 11:57 AM
Registered User
 
Join Date: Nov 2006
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default regular expressions vs split (speed issues)

Hi,

I have some code which removes a predetermined set of words such as "to, of , and, or" from strings, The idea being that I can there compare strings such as "15 to 25", "15 and 25", "15 or 25" and they will match.

I'm currently achieving this using the regular expression replace method but I'm finding this is a massive performance hit on my application (approx 300 percent)

I've thought about using split then examining each array element but without a native splice function it seems to me that removing elements from the middle of an array is somewhat tricky.

Should I knuckle down and write a custom splice function or if there a far simpler method that I'm not aware of?

many thanks, see below for RegExp function

Code:
Public Function cleanse(ByRef strInput)

Dim strReturn As String

Dim regRemove As RegExp
Set regRemove = New RegExp

With regRemove
    .Pattern = "to|yrs|&|and|or|of"
    .IgnoreCase = True
    .Global = True
End With

strReturn = regRemove.Replace(strInput, "")

cleanse = strReturn

End Function
 
Old March 8th, 2007, 06:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 173
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Why don't you try using the worksheet function SUBSTITUTE instead? Worksheet functions are precomplied so tend to work quicker the UDFs

Maccas






Similar Threads
Thread Thread Starter Forum Replies Last Post
Do I need regular expressions..? ypomonh XSLT 2 May 20th, 2007 05:09 PM
Regular Expressions mega Beginning PHP 1 February 5th, 2007 05:31 PM
Regular Expressions The_Iceman ASP.NET 2.0 Basics 0 September 29th, 2006 05:06 AM
Speed issues lryckman Access 2 November 30th, 2005 09:21 AM
regular expressions help kyootepuffy Classic ASP Databases 2 September 10th, 2003 01:37 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.