all groups > dotnet sdk > june 2005 >
You're in the

dotnet sdk

group:

char.IsDigit vs char.IsNumber


char.IsDigit vs char.IsNumber David Thielen
6/12/2005 1:45:01 PM
dotnet sdk:
Hi;

What's the difference?

--
Re: char.IsDigit vs char.IsNumber Mattias Sjögren
6/12/2005 11:57:20 PM
David,

[quoted text, click to view]

IsNumber returns true for a larger set of characters. "IsDigit"
includes only characters with the UnicodeCategory DecimalDigitNumber,
whereas "IsNumber" also include the LetterNumber and OtherNumber
categories.



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Re: char.IsDigit vs char.IsNumber David Thielen
6/15/2005 5:47:02 AM
Hi;

I'm assuming that if I am checking if int.Parse will worjk IsDigit is the
one to use then?

--
thanks - dave


[quoted text, click to view]
Re: char.IsDigit vs char.IsNumber v-phuang NO[at]SPAM online.microsoft.com (
6/16/2005 5:40:23 AM
Hi

This depends on which number you will use.
Char.IsDigit Method
This method determines if a Char is a radix-10 digit.

DecimalDigitNumber
Supported by the .NET Compact Framework.
Indicates that the character is a decimal digit; that is, in the range 0
through 9. Signified by the Unicode designation "Nd" (number, decimal
digit). The value is 8.

Char.IsNumber
This method determines if a Char is of any numeric Unicode category
Valid numbers are members of the following categories in UnicodeCategory:
DecimalDigitNumber, LetterNumber, or OtherNumber.

LetterNumber
Supported by the .NET Compact Framework.
Indicates that the character is a number represented by a letter, instead
of a decimal digit; for example, the Roman numeral for five, which is 'V'.
Signified by the Unicode designation "Nl" (number, letter). The value is 9.

OtherNumber
Supported by the .NET Compact Framework.
Indicates that the character is a number that is neither a decimal digit
nor a letter number; for example, the fraction 1/2. Signified by the
Unicode designation "No" (number, other). The value is 10.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfsystemglobalizationunicodecategoryclasstopic.asp


That is to say if you just wants to parse the string consist of 0-9,
IsDigit is enough, or you need to use the IsNumber.
IsNumber will consider the 'a' as a radix-16 number.




Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Re: char.IsDigit vs char.IsNumber David Thielen
6/16/2005 1:26:05 PM
This is an excellent explination of isDigit vs isNumber - thanks - dave


--
thanks - dave


[quoted text, click to view]
Re: char.IsDigit vs char.IsNumber Mattias Sjögren
6/16/2005 9:50:22 PM
David,

[quoted text, click to view]

I wouldn't do that, it would exclude valid characters like '-'. In
..NET framework v2.0 I'd use the Int32.TryParse method instead. You may
also want to check

Char.IsDigit() matches more than just "0" through "9"
http://blogs.msdn.com/oldnewthing/archive/2004/03/09/86555.aspx



Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Re: char.IsDigit vs char.IsNumber v-phuang NO[at]SPAM online.microsoft.com (
6/17/2005 7:01:46 AM
Hi

I am glad that helps you.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
AddThis Social Bookmark Button