Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Removing Non-Numeric Characters from a String 1

Status
Not open for further replies.

idbr

MIS
May 1, 2003
247
GB
Hi,

I need to take a string and remove any non-numeric characters (whilst preserving any decimalisation), e.g.

Bob is 50
Price = 29.99
I have 312 tasks

Should become

50
29.99
312

My data sits in a single field in an Access table.

I was hoping someone might have a more creative solution then looking at each individual character in the string - any suggestions?

I run A2002 on an XP machine.

Thanks, Iain
 
How clean is your environment PHV. In other words, what other applications, services, or other tasks are running in the background while you perform these tests? An how can you guarantee that none of those other tasks haven't skewed your results?

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Another point to note
RoyVidar said:
I doubt the efficiency on single fields exceeds the character by character approach, but just for the fun of it.
Any timing tests must take into account the length of the string being tested. The character by character appropach is extremely dependant on the length of the string, and the longer the string, the longer the char by char approach will take. The Regular Expression will be far less influenced by the length of the string.

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
The Regular Expression will be far less influenced by the length of the string
Really ?
How clean is your environment PHV. In other words, what other applications, services, or other tasks are running in the background while you perform these tests? An how can you guarantee that none of those other tasks haven't skewed your results?
The results I posted was an average of 20 times the 1000000 iterations on the same machine, one time the RoyVidar function, next time my function and so forth.
 
As far as benchmarking, I finally got some time on our benchmark machine (my request for this wasn't a very high priority). This lab machine is dedicated to timing algorithms. This is a stand-alone machine (no network, no internet), all services, tasks, and processes eliminated, except only those absolutely necessary for windows to allow the timing application to run. This application tests only the algorithms under investigation, and it not affected by execution of the application itself. For example, if you want to measure how long it takes a statement to execute, and you've placed that statement in a loop, this programs factors out the time to do the loop, so that only time of the statement is actually measured. The timer used is the QueryPerformanceCounter.

In this case, for the string "Price299", the CharByChar approach was about 2.7 times faster than the RegExp approach with scoring as follows: CBC-0.0915, RE-0.24945.

However, using the string, "The standard unit price for this item of merchandise is 299.99", the RegExp approach was faster (0.3483) than the CharByChar approach (0.44325).

So, for short string (<= ~45 chars before the number), the CharByChar approach is preferable. For string longer than that, the RegExp approach is superior, and the longer the string, better the relative performance of the RegExp.

Note: You should see how the RegExp Replace function compares to the built-in VB Replace function once you get into longer strings or multiple replaces. We ran those tests about 18 months ago and it was a shock to how much better RegExp performed over the built-in function.

So PHV, Really? Yes, Really. I appreciate that you ran your tests many, many times and averaged the results, with the feeling that any anomolies created by background processes would be evened out over time. Maybe, maybe not, how can any of us be sure. It seems to me that 15 secs (CharByChar) to 22 secs (RegExp) for the string "Price999", seems a little close, although the CharByChar should be faster.

Nevertheless, you still haven't aswered my questions, how sterile is you testing environment, and how isolated is it from the vagaries of a normal Windows production environment, or external interrupts that can come from a LAN/WAN configuration. Which timer are you using?

Good Luck
--------------
To get the most from your Tek-Tips experience, please read FAQ181-2886
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top