.NETGURU
Char.IsNumber()
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcs' list.


Paul D. Murphy
I remember a thread a while back asking about IsNumeric in C#. The Char
type (something I never really need to use unless parsing for a Split())
exposes a static method IsNumber(); So I think the best way to approach
the IsNumeric might be something like this.

public bool IsNumeric
{
    foreach(System.Char c in System.String.ToCharArray())
    {
        if(!Char.IsNumber(c))
            return false;
    }

    return true;
}

    Paul D. Murphy
    Click here to reveal e-mail address
    "Teamwork is a lot of people doing what I say."

-----Original Message-----
From: Julian Voelcker [mailto:Click here to reveal e-mail address]=20
Sent: Friday, July 12, 2002 5:26 AM
To: aspngcs
Subject: [aspngcs] Re: Daylight Saving Time Problems

On Thu, 11 Jul 2002 11:34:15 -0400, Ryan Trudelle-Schwarz wrote:
[Original message clipped]

No, I don't really want to use that because the client will have to=20
change the times they enter into UTC, which I don't think is=20
satisfactory.

Cheers,

Julian Voelcker
The Virtual World (UK) Limited
Cirencester, United Kingdom

| [aspngcs] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp =3D JOIN/QUIT

Reply to this message...
 
    
Minh Truong
[Original message clipped]

Of course, this wouldn't work for strings like "2.99", "1E3", "1,000", or
"-2"

Reply to this message...
 
    
Remas Wojciechowski
As someone mentioned already, this method will yield faulty results for a
range of numbers. I belong to the fraction of try&catch on double.Parse()
proponents.

Remas
http://www.aspalliance.com/remas

----- Original Message -----
From: "Paul D. Murphy" <Click here to reveal e-mail address>
To: "aspngcs" <Click here to reveal e-mail address>
Sent: Friday, July 12, 2002 4:56 PM
Subject: [aspngcs] Char.IsNumber()

I remember a thread a while back asking about IsNumeric in C#. The Char
type (something I never really need to use unless parsing for a Split())
exposes a static method IsNumber(); So I think the best way to approach
the IsNumeric might be something like this.

public bool IsNumeric
{
foreach(System.Char c in System.String.ToCharArray())
{
if(!Char.IsNumber(c))
return false;
}

return true;
}

Paul D. Murphy
Click here to reveal e-mail address
"Teamwork is a lot of people doing what I say."

-----Original Message-----
From: Julian Voelcker [mailto:Click here to reveal e-mail address]
Sent: Friday, July 12, 2002 5:26 AM
To: aspngcs
Subject: [aspngcs] Re: Daylight Saving Time Problems

On Thu, 11 Jul 2002 11:34:15 -0400, Ryan Trudelle-Schwarz wrote:
[Original message clipped]

No, I don't really want to use that because the client will have to
change the times they enter into UTC, which I don't think is
satisfactory.

Cheers,

Julian Voelcker
The Virtual World (UK) Limited
Cirencester, United Kingdom

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

| [aspngcs] member Click here to reveal e-mail address = YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp = JOIN/QUIT

Reply to this message...
 
    
Ryan Trudelle-Schwarz
Any perf tests to see if that is less intensive then running a regex on
it?
I still belong to the faction of "try/catch only when absolutely
necessary, never as part of the logic" folks ;)

-> -----Original Message-----
-> From: Remas Wojciechowski [mailto:Click here to reveal e-mail address]
->
-> As someone mentioned already, this method will yield faulty results
for a
-> range of numbers. I belong to the fraction of try&catch on
double.Parse()
-> proponents.
->
-> Remas
-> http://www.aspalliance.com/remas
->
-> ----- Original Message -----
-> From: "Paul D. Murphy" <Click here to reveal e-mail address>
->
-> I remember a thread a while back asking about IsNumeric in C#. The
Char
-> type (something I never really need to use unless parsing for a
Split())
-> exposes a static method IsNumber(); So I think the best way to
approach
-> the IsNumeric might be something like this.
->
-> public bool IsNumeric
-> {
-> foreach(System.Char c in System.String.ToCharArray())
-> {
-> if(!Char.IsNumber(c))
-> return false;
-> }
->
-> return true;
-> }
->
-> Paul D. Murphy

---
[This E-mail scanned for viruses by Declude Virus]

Reply to this message...
 
 
System.Char
System.DateTime
System.String




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification