473,326 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

strip non-numeric characters

Is there simple way to take a string that should be all numeric (like a
credit card number) and strip out anything that isn't a digit? In the past
I've done this in VFP using the IsDigit() function, looping through each
character. It was a little awkward, but worked. Is there something similar,
or better for vb.net?

Thanks!

Matt
Nov 18 '05 #1
3 7511
The IsNumeric function should fill the bill...

Dim MyVar As Object
Dim MyCheck As Boolean
' ...
MyVar = "53" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "459.95" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns True.
' ...
MyVar = "45 Help" ' Assign value.
MyCheck = IsNumeric(MyVar) ' Returns False.

Regards,
January Smith

"MattB" <so********@yahoo.com> wrote in message
news:2h************@uni-berlin.de...
Is there simple way to take a string that should be all numeric (like a
credit card number) and strip out anything that isn't a digit? In the past
I've done this in VFP using the IsDigit() function, looping through each
character. It was a little awkward, but worked. Is there something similar, or better for vb.net?

Thanks!

Matt

Nov 18 '05 #2
I would try Regex. You can look for \d and pull all instances, then concat
back the resulting array. There are a couple of other ways to work with
this.

Note that VB.NET still has IsNumber() or IsNumeric() [forget which one], so
you can still loop and test, if you want to go with VB.NET.

Another option is convert to a char array and test the numeric value of each
char. The ASCII value for numbers is extremely predictable.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

************************************************
Think Outside the Box!
************************************************
"MattB" <so********@yahoo.com> wrote in message
news:2h************@uni-berlin.de...
Is there simple way to take a string that should be all numeric (like a
credit card number) and strip out anything that isn't a digit? In the past
I've done this in VFP using the IsDigit() function, looping through each
character. It was a little awkward, but worked. Is there something similar, or better for vb.net?

Thanks!

Matt

Nov 18 '05 #3
You can use the Regex.Replace method to check for any characters (\w) and replace them with an empty string. The result that would come out is a string that is all numeric.
Nov 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Dr Clue | last post by:
I'm not really an expert with RegExp() , although I do use it. The problem I have is that I want to strip comments out of a CSS file using RegExp() The reason is that I'm loading and parsing to...
6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
2
by: Gustavo Randich | last post by:
Hello, (Using DB2/LINUX 8.2.0) After compiling the STRIP migration UDF (found at http://www-106.ibm.com/developerworks/db2/library/samples/db2/0205udfs/), if I try to execute: values...
16
by: jcf | last post by:
I need to do the following: Our application builds information from a string that is stored in a buffer that can be any of the following formats: ABCD0102, ABCDEF0102, AB*CD*01*02, AB*CDEF*01*02....
5
by: RedEye | last post by:
Hello, I need to toss together a quick pocket pc app that uses a magnetic strip reader as it's primary method of input. I was wonder if there are any open source API's for this. Thanks for...
5
by: dan.j.weber | last post by:
I'm using Python 2.3.5 and when I type the following in the interactive prompt I see that strip() is not working as advertised: >>>s = 'p p:p' >>>s.strip(' :') 'p p:p' Is this just me or...
6
by: rtilley | last post by:
s = ' qazwsx ' # How are these different? print s.strip() print str.strip(s) Do string objects all have the attribute strip()? If so, why is str.strip() needed? Really, I'm just curious......
4
by: Steve | last post by:
Hi, I'm a complete PHP n00b slowly finding my way around I'm using the following function that I found on php.net to strip out html and return only the text. It works well except for when you...
6
by: eight02645999 | last post by:
hi can someone explain strip() for these : 'example' when i did this: 'abcd,words.words'
4
by: Poppy | last post by:
I'm using versions 2.5.2 and 2.5.1 of python and have encountered a potential bug. Not sure if I'm misunderstanding the usage of the strip function but here's my example. var = "detail.xml"...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.