473,382 Members | 1,421 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,382 software developers and data experts.

count occurances of digits in a string

any fast way to do this? I just need to check if if a string which could
have a lot of characters in it if it has numbers and count the number of
numbers in the string. thanks!
Jun 27 '07 #1
2 3052
Smokey Grindle wrote:
any fast way to do this? I just need to check if if a string which could
have a lot of characters in it if it has numbers and count the number of
numbers in the string. thanks!
Use the Matches method in the Regex class with a regular expression
pattern as "\d+" to find all occurances of digits.

Depending on if you want to count numbers or count digits (which isn't
really clear), get the number of matches or add the lengths of the matches.

--
Göran Andersson
_____
http://www.guffa.com
Jun 27 '07 #2
On Jun 27, 11:17 am, "Smokey Grindle" <nos...@nospam.comwrote:
any fast way to do this? I just need to check if if a string which could
have a lot of characters in it if it has numbers and count the number of
numbers in the string. thanks!
I thinking something like this:

' Assumes Imports System.Text.RegularExpressions

Dim s As String = "Some string 454 with numbers in it. 4234"
Dim regex As New Regex("\d")
MsgBox(regex.Matches(s).Count)

Thanks,

Seth Rowe

Jun 27 '07 #3

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

Similar topics

3
by: Xah Lee | last post by:
if i have mytext.replace(a,b) how to find out many many occurances has been replaced? Xah xah@xahlee.org ∑ http://xahlee.org/
4
by: grocery_stocker | last post by:
#include <iostream> //for cin and cout #include <iomanip> // for setw() #include <string> // for strlen() strcmp() strrev() #include <fstream> //ifstream and ofstream: file (input & output)...
1
by: Grammie | last post by:
I need a report that looks like this: 1. Number of Enrollees as of Today: (count of everyone in query){can count last names) 2. Total Active People (count of everyone with "A" as...
17
by: keith | last post by:
I am trying to get a exact count of different distinct entries in an Access column. At first, I was trying to work with three columns, but I've narrowed it down to one to simplify it. I've searched...
24
by: Derek Hart | last post by:
Is there an efficient line of code to count the number of instances of one string within another. If I have the sentence: "I want to go to the park, and then go home." It would give me a...
2
by: Sathyaish | last post by:
I have a CSV file like so: "HDR",20060629133932,"9845","9083","0010" 1,"3","000000000690","000007","rsM4hJXR5Ik0O8RWghjtDBlUVAOZq7tO","BAR","0010","","",20.00...
0
by: uninvitedm | last post by:
Heya I've got a table of invoices, which have dates and customer_id's. What I need to get is the number of occurances for this customer for a 12-month range window. For example, if there's an...
4
by: nirvana | last post by:
I need to count the number of continous character occurances(more than 1) in a file, and replace it with a compressed version, like below XYZAAAAAAAADEFAAcdAA --XYZ8ADEF2Acd2A Thanks Sumod
1
by: jlt206 | last post by:
This code <?php include("counter.php")?> on the webpage produces the count number. (function code below) I want to place the current number into a variable $MemberNo or into a FormField to be sent...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.