IsDigit...

  • Thread starter Thread starter Per Rollvang
  • Start date Start date
P

Per Rollvang

Hi All!

I have a problem with hex strings when using Char.IsDigit().

The hex strings(i.e. a CRC32 checksum) get a false result for letters A-F...

MSDN tell me that:

[Char.IsDigit()] Indicates whether a Unicode character is categorized as a
decimal digit or hexadecimal number.

My method goes like this:

public bool IsNumeric(string sIn)
{
bool bRet = true;
string s = sIn.ToUpper();
char[] tmp = s.ToCharArray();

for (int i = 0; i < tmp.Length;i++)
{
if (!char.IsDigit(sIn,i))
{
bRet = false;
break;
}
}
return bRet;
}


Anyone?

TIA

Per Rollvang
 
Eh...

Some inconsistencies as I tried to snip a long bit of my code, but I don't
get the 'digits' A-F to report as numeric values...

Kind of what I was trying to get along... : )

Anyone?

-Per
 
Hi..

All isChar can do is check individual character

Unfortunatly this means, IsDigit only accepts/checks a single char, which means it has no way to tell if A-F is in the context of A-z (alphabet) or hex..

I suspect in your code you will have to handle the extra A-F yourself..

Cheer
Eddi
 
Per said:
Hi All!

I have a problem with hex strings when using Char.IsDigit().

The hex strings(i.e. a CRC32 checksum) get a false result for letters A-F...

MSDN tell me that:

[Char.IsDigit()] Indicates whether a Unicode character is categorized as a
decimal digit or hexadecimal number.

Are you sure? What I see in MSDN is:

"Char.IsDigit Method

Indicates whether the specified Unicode character is categorized as a
decimal digit.

public static bool IsDigit(char);

Indicates whether the character at the specified position in a specified
string is categorized as a decimal digit.

public static bool IsDigit(string, int);"

<snip>
 
Per said:
public bool IsNumeric(string sIn)

double.TryParse is incredibly flexible allowing for culturally aware input
in any valid numeric format supported by the local system. It returns a bool
indicating whether the conversion was successful.

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

http://code.acadx.com
(Pull the pin to reply)
 
Per Rollvang said:
I have a problem with hex strings when using Char.IsDigit().

The hex strings(i.e. a CRC32 checksum) get a false result for letters A-F...

MSDN tell me that:

[Char.IsDigit()] Indicates whether a Unicode character is categorized as a
decimal digit or hexadecimal number.

Where does it say that? It doesn't have it in my version of MSDN, and I
can't find it on msdn.microsoft.com...
 
Jon Skeet said:
Per Rollvang said:
MSDN tell me that:

[Char.IsDigit()] Indicates whether a Unicode character is categorized as a
decimal digit or hexadecimal number.

Where does it say that? It doesn't have it in my version of MSDN, and I
can't find it on msdn.microsoft.com...

Hmm... Searched, and did not find it. What was I drinking last night? Must
stop doing that...

This is a mystery like 'the dissappearing socks' :..

-Per
 
Frank Oquendo said:
double.TryParse is incredibly flexible allowing for culturally aware input
in any valid numeric format supported by the local system. It returns a bool
indicating whether the conversion was successful.

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

http://code.acadx.com
(Pull the pin to reply)

Thanks Frank, it worked like a charm...

-Per
 
Back
Top