473,671 Members | 2,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to remove all non-digit characters from a string

Hello,

Is there a way to remove all non-digit characters from a string in one call?
string.Replace( ) methods don't allow this.

thanks!
Nov 15 '05 #1
7 11093
Use regex

--
Regards,
Tamir Khason
Especially those days you need a flexible IT service provider that can meet
your needs through a broad set of offerings.
TCON - A technology company that understands your business.
www.tcon.co.il

"Zeng" <zz*@nonospam.c om> wrote in message
news:Oa******** ******@TK2MSFTN GP10.phx.gbl...
Hello,

Is there a way to remove all non-digit characters from a string in one call? string.Replace( ) methods don't allow this.

thanks!

Nov 15 '05 #2
string s = Regex.Replace(o Box.Text,"\\D", "")

or "\\d" one means digit the other one means non digit. i forget at the
moment which is which.
--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"Tamir Khason" <ta**********@t con-NOSPAM.co.il> wrote in message
news:#T******** ******@TK2MSFTN GP09.phx.gbl...
Use regex

--
Regards,
Tamir Khason
Especially those days you need a flexible IT service provider that can meet your needs through a broad set of offerings.
TCON - A technology company that understands your business.
www.tcon.co.il

"Zeng" <zz*@nonospam.c om> wrote in message
news:Oa******** ******@TK2MSFTN GP10.phx.gbl...
Hello,

Is there a way to remove all non-digit characters from a string in one

call?
string.Replace( ) methods don't allow this.

thanks!


Nov 15 '05 #3
Regex.Replace(s Input,"\d","")
"Zeng" <zz*@nonospam.c om> wrote in message
news:Oa******** ******@TK2MSFTN GP10.phx.gbl...
Hello,

Is there a way to remove all non-digit characters from a string in one call? string.Replace( ) methods don't allow this.

thanks!

Nov 15 '05 #4
Acutally, it should be Regex.Replace(m yInput, @"\d", string.Empty);
"William Ryan" <do********@com cast.nospam.net > wrote in message
news:ee******** *****@TK2MSFTNG P12.phx.gbl...
Regex.Replace(s Input,"\d","")
"Zeng" <zz*@nonospam.c om> wrote in message
news:Oa******** ******@TK2MSFTN GP10.phx.gbl...
Hello,

Is there a way to remove all non-digit characters from a string in one

call?
string.Replace( ) methods don't allow this.

thanks!


Nov 15 '05 #5
good idea on the string.empty the @ is optional

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"William Ryan" <do********@com cast.nospam.net > wrote in message
news:ue******** ******@TK2MSFTN GP12.phx.gbl...
Acutally, it should be Regex.Replace(m yInput, @"\d", string.Empty);
"William Ryan" <do********@com cast.nospam.net > wrote in message
news:ee******** *****@TK2MSFTNG P12.phx.gbl...
Regex.Replace(s Input,"\d","")
"Zeng" <zz*@nonospam.c om> wrote in message
news:Oa******** ******@TK2MSFTN GP10.phx.gbl...
Hello,

Is there a way to remove all non-digit characters from a string in one

call?
string.Replace( ) methods don't allow this.

thanks!



Nov 15 '05 #6
Yeah, I flip back and forth between C# and VB.NET a lot, so I always code
like the other one for the first few hours. Someday I'll remember it @.
"Alvin Bruney" <vapordan_spam_ me_not@hotmail_ no_spamhotmail. com> wrote in
message news:ul******** ******@TK2MSFTN GP11.phx.gbl...
good idea on the string.empty the @ is optional

--
-----------
Got TidBits?
Get it here: www.networkip.net/tidbits
"William Ryan" <do********@com cast.nospam.net > wrote in message
news:ue******** ******@TK2MSFTN GP12.phx.gbl...
Acutally, it should be Regex.Replace(m yInput, @"\d", string.Empty);
"William Ryan" <do********@com cast.nospam.net > wrote in message
news:ee******** *****@TK2MSFTNG P12.phx.gbl...
Regex.Replace(s Input,"\d","")
"Zeng" <zz*@nonospam.c om> wrote in message
news:Oa******** ******@TK2MSFTN GP10.phx.gbl...
> Hello,
>
> Is there a way to remove all non-digit characters from a string in one call?
> string.Replace( ) methods don't allow this.
>
> thanks!
>
>



Nov 15 '05 #7
Thanks, it should be "\D" .

"William Ryan" <do********@com cast.nospam.net > wrote in message
news:ue******** ******@TK2MSFTN GP12.phx.gbl...
Acutally, it should be Regex.Replace(m yInput, @"\d", string.Empty);
"William Ryan" <do********@com cast.nospam.net > wrote in message
news:ee******** *****@TK2MSFTNG P12.phx.gbl...
Regex.Replace(s Input,"\d","")
"Zeng" <zz*@nonospam.c om> wrote in message
news:Oa******** ******@TK2MSFTN GP10.phx.gbl...
Hello,

Is there a way to remove all non-digit characters from a string in one

call?
string.Replace( ) methods don't allow this.

thanks!



Nov 15 '05 #8

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

Similar topics

9
30761
by: chris | last post by:
is there a quick and easy way to check a string for non numeric characters ? i have thought of making a routine to check each character to confirm it is 0 - 9 but was wondering if there was a quicker way???
32
4509
by: Adrian Herscu | last post by:
Hi all, In which circumstances it is appropriate to declare methods as non-virtual? Thanx, Adrian.
2
1887
by: ElGordo | last post by:
I was recently given .Net project files to work on. When I open the Solution file in VS.Net, I always get the message: "The solution appears to be under source control, but its binding information cannot be found. It is possible that the MSSCCPRJ.SCC file or another item that holds the source control settings for the solution, has been deleted. Because it is not possible to recover this missing information automatically, the projects...
2
1346
by: SStory | last post by:
How can I strong name my assembly if it references 3rd part non-strong named dlls? I just want my part strong named--I don't care about their part. Thanks, Shane
39
3176
by: utab | last post by:
Dear all, Is there a clear distinction how to decide which functions to be members of a class and which not How is your attitude (Your general way from your experiences ...) "If the function changes the state of the object, it ought to be a member of that object." Reference Accelerated C++, A. Koenig, page 159.
80
7859
by: Andrew R | last post by:
Hi I'm creating a series of forms, each with with around 15-20 text boxes. The text boxes will show data from tables, but are unbound to make them more flexible. I want the form to be used for both adding new data and modifying existing data. I have created a save button on the form. When the user clicks the save button, the code checks to see if there
2
1224
by: Jarry | last post by:
I was editing a huge XML file that a friend of mine had made and I didn't need some of the tags. WHen I was finished editing it, I realised I had a lot of information between tags, in no man's land. eg: <team> <player> <name>David Beckham</nameREAL MADRID <positionRight Midfield </position> </player> </team>
7
6295
by: Benjamin Goudey | last post by:
I have a very large list of integers representing data needed for a histogram that I'm going to plot using pylab. However, most of these values (85%-95%) are zero and I would like to remove them to reduce the amount of memory I'm using and save time when it comes to plotting the data. To do this, I'm trying to find the best way to remove all of the zero values and produce a list of indices of where the non-zero values used to be. For...
4
17034
by: puzzlecracker | last post by:
if I provide a key of element that doesn't exist in the set, and I call set.erase(nonInSetKey), does standard guarantee that nothing "BAD" will happen, in fact, nothing at all will happen. Does it make sense to check first whether key is in the set before removing it?
4
4241
by: kshw | last post by:
Hi, I'm trying to remove non-stop words from a text file using regular expresions but it is not working. I used something like ('^?or') in order to avoid removing (or) from the mibble of words e.g. morning. Temp = Original_File = open('out.txt', 'r') Original_File_Content = Original_File.read() Original_File.close() Temp.append("".join(Original_File_Content)) FileString = "".join(Temp)
0
8476
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8670
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4407
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2812
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2051
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.