Wrox Programmer Forums
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 26th, 2007, 10:40 PM
Authorized User
 
Join Date: Feb 2007
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default strings

How do I get my program to check that a string contains only numbers? Any help would be nice.

There are 10 types of people - Those who understand binary, and those who don't.
__________________
There are 10 types of people - Those who understand binary, and those who don\'t.
http://bschleusner.googlepages.com/home
 
Old February 26th, 2007, 10:48 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

There are lots of ways to do this:

1. In your project you can add a reference to Microsoft.VisualBasic and use the IsNumeric function that is contained within that Namespace.

2. You can loop through the string char by char and call Char.IsDigit()

3. You can use regular expressions to determine if the string contains only numeric values.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
^^Took that from planoie's profile^^
^^Modified text taken from gbianchi profile^^
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html

Discussion:
http://p2p.wrox.com/topic.asp?TOPIC_ID=56429
 
Old February 26th, 2007, 11:44 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Also consider TryParse method of your numeric data types.
EG
double.TryPass("1.54",result)


======================================
"They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad."
--Shakespeare
======================================
 
Old February 27th, 2007, 11:46 PM
Authorized User
 
Join Date: Feb 2007
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks alot! I am trying to avoid as many of my old time consuming qb habits as posible with c#, and am trying to do things as efficient as posible.

There are 10 types of people - Those who understand binary, and those who don't.





Similar Threads
Thread Thread Starter Forum Replies Last Post
strings RoniR VB.NET 2002/2003 Basics 1 May 4th, 2007 02:55 PM
Strings ldoodle Classic ASP Basics 0 June 28th, 2005 09:26 AM
strings Moharo Pro PHP 2 May 17th, 2004 06:15 AM
strings... slowhand BOOK: ASP.NET Website Programming Problem-Design-Solution 1 January 5th, 2004 06:27 AM
strings slowhand SQL Server 2000 1 January 5th, 2004 12:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.