473,399 Members | 3,603 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,399 software developers and data experts.

Find only digits in string

How to filter out only digits from a string?
i.e. fgfdg435fdg7dgf5:df,54 => 4357554
Thanks

Nov 21 '05 #1
7 7738
CT
There are several ways, including using a regular expression. You can also
do this:

Dim full As String = "jhg345gvbjk36hg53j5j3hg5j3"
Dim validChars As String = "0123456789"
Dim numbers As String
Dim allChars() As Char = full.ToCharArray

For Each ch As Char In allChars
If validChars.IndexOf(ch) <> -1 Then
numbers &= ch
End If
Next

MessageBox.Show(numbers)
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
How to filter out only digits from a string?
i.e. fgfdg435fdg7dgf5:df,54 => 4357554
Thanks

Nov 21 '05 #2
CT
Oops, forgot the RegEx example:

numbers = Regex.Replace(full, "[aA-zZ]+", "")
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

"CT" <ca******@spammersgoawaydotnetservices.biz> wrote in message
news:OE*************@tk2msftngp13.phx.gbl...
There are several ways, including using a regular expression. You can also
do this:

Dim full As String = "jhg345gvbjk36hg53j5j3hg5j3"
Dim validChars As String = "0123456789"
Dim numbers As String
Dim allChars() As Char = full.ToCharArray

For Each ch As Char In allChars
If validChars.IndexOf(ch) <> -1 Then
numbers &= ch
End If
Next

MessageBox.Show(numbers)
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
How to filter out only digits from a string?
i.e. fgfdg435fdg7dgf5:df,54 => 4357554
Thanks


Nov 21 '05 #3
Hi,

I would use the char's isdigit method instead.

For Each ch As Char In allChars
If Char.IsDigit(ch) Then
numbers &= ch
End If
Next
Ken
---------------------
"CT" <ca******@spammersgoawaydotnetservices.biz> wrote in message
news:OE*************@tk2msftngp13.phx.gbl...
There are several ways, including using a regular expression. You can also
do this:

Dim full As String = "jhg345gvbjk36hg53j5j3hg5j3"
Dim validChars As String = "0123456789"
Dim numbers As String
Dim allChars() As Char = full.ToCharArray

For Each ch As Char In allChars
If validChars.IndexOf(ch) <> -1 Then
numbers &= ch
End If
Next

MessageBox.Show(numbers)
--
Carsten Thomsen
Enterprise Development with VS .NET, UML, AND MSF
http://www.apress.com/book/bookDisplay.html?bID=105
Communities - http://community.integratedsolutions.dk

"Nikolay Petrov" <jo******@mail.bg> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...
How to filter out only digits from a string?
i.e. fgfdg435fdg7dgf5:df,54 => 4357554
Thanks


Nov 21 '05 #4
"Nikolay Petrov" <jo******@mail.bg> schrieb:
How to filter out only digits from a string?
i.e. fgfdg435fdg7dgf5:df,54 => 4357554


\\\
Dim s As String = "&A$§23zb4-u9%%8Z"
MsgBox(Regex.Replace(s, "[^0-9]", ""))
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
I'll use Ken's example, bucause of sum UNICODE chars in my string.
Thanks to all

Nov 21 '05 #6
Nikolay,

Than I see a nice implementation given by Herfried from the Regex and than
you are not using it.

However he did not give you the complete reference that is needed.
\\\
Dim s As String = "&A$§23zb4-u9%%8Z"
MessageBox.Show(System.Text.RegularExpressions.Reg ex.Replace(s, "[^0-9]",
""))
///

I hope this helps,

Cor

"Nikolay Petrov" <jo******@mail.bg> schreef in bericht
news:11**********************@g44g2000cwa.googlegr oups.com...
I'll use Ken's example, bucause of sum UNICODE chars in my string.
Thanks to all

Nov 21 '05 #7
Thanks Cor
awesome

Nov 21 '05 #8

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

Similar topics

14
by: Westcoast Sheri | last post by:
What is the most efficient way of extracting the first two digits in a string? The following is wrong for me, because it only gives me the first instance of two digits together: $string =...
13
by: CHRISTOF WARLICH | last post by:
Hi, does anyone know of an efficient way to find the number of digits (i.e. the most significant position that is 1) of a binary number? What I found so far is: - digits = (int) log2(number),...
8
by: jquest | last post by:
Hi Again; I have had help from this group before and want to thank everyone, especially PCDatasheet. My database includes a field called HomePhone, it uses the (xxx)xxx-xxx format to include...
18
by: Kuljit | last post by:
I am doing Engineering(B.Tech) in Computer Science. I have a question for which i am struggling to write a C code(program). It struck me when we were being taught about a program which counts the...
4
by: Anoop | last post by:
Hi All I am getting two different outputs when i do an operation using string.digits and test.isdigit(). Is there any difference between the two. I have given the sample program and the output ...
109
by: jmcgill | last post by:
Hello. Is there a method for computing the number of digits, in a given numeric base, of N factorial, without actually computing the factorial? For example, 8! has 5 digits in base 10; 10! has...
5
by: zaie | last post by:
The files I'm referring to can be found here: http://www.moxybox.com/programming After going through this in debugger numerous times, I can't figure out why this code continues to return false:...
7
by: Michael Howes | last post by:
MSDN documentation for format strings seems ambiguous. It's says things like "significant digits or number of decimal places" all over the place. Well those two things are different. How do I...
0
by: zephyrus360 | last post by:
This is about a technique to find the mod of a very large integer with a normal small integer. I recently encountered this problem when I needed to compute the modulus of a very large number with...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.