473,287 Members | 1,926 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,287 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 7733
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...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
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: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
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...

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.