Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

IsHex() ??

0 views
Skip to first unread message

Tremendo

unread,
Feb 9, 2007, 4:29:08 AM2/9/07
to
bool Char.IsHex(char c)

Is there any function like that?

Char.IsNumber() definitely does not work.

Thank you.

ChrisM

unread,
Feb 9, 2007, 4:35:36 AM2/9/07
to
In message gifos2tdu64nca3ku...@4ax.com,
Tremendo <nom...@hatespam.com> Proclaimed from the tallest tower:

:: bool Char.IsHex(char c)


::
:: Is there any function like that?
::
:: Char.IsNumber() definitely does not work.
::
:: Thank you.

Not aware of one, but it would be a pretty easy function to write...

--
Regards,
Chris.
(Remove Elvis's shoes to email me)


Tremendo

unread,
Feb 9, 2007, 4:55:36 AM2/9/07
to
On Fri, 9 Feb 2007 09:35:36 -0000, "ChrisM" <chris_ma...@suedeyahoo.com> wrote:

>In message gifos2tdu64nca3ku...@4ax.com,
>Tremendo <nom...@hatespam.com> Proclaimed from the tallest tower:
>
>:: bool Char.IsHex(char c)
>::
>:: Is there any function like that?
>::
>:: Char.IsNumber() definitely does not work.
>::
>:: Thank you.
>
>Not aware of one, but it would be a pretty easy function to write...

Sure, but I am amazed that, among the hundreds of functions that the framework includes, they forgot
to include one so useful as that.


BTW, is there anything shorter than this?

if (Char.IsDigit(c) || ((Char.ToLower(c) >='a') && (Char.ToLower(c) <='f')))
...


I mean, is there any function like this?
bool Char.InSet(char c,string set_of_case_insensitive_characters)

that I could call like this

if (Char.InSet(c,"0123456789ABCDEF"))
...

Thanks

Fabrizio Romano

unread,
Feb 9, 2007, 5:21:59 AM2/9/07
to
private bool IsHex(char c) {
return Char.IsLetterOrDigit(c) && Char.ToLower(c)<='f';
}

this should work.
Cheers,
Fabrizio

"Tremendo" <nom...@hatespam.com> wrote in message
news:ahgos2tltqvpoke89...@4ax.com...

rossum

unread,
Feb 9, 2007, 9:38:05 AM2/9/07
to
On Fri, 09 Feb 2007 10:29:08 +0100, Tremendo <nom...@hatespam.com>
wrote:

bool System.Uri.IsHexDigit(char) would seem to be what you want.

rossum

Luc E. Mistiaen

unread,
Feb 9, 2007, 11:04:38 AM2/9/07
to
Something like

if ("0123456789ABCDEF".IndexOf(c) >= 0)...

JR

unread,
Feb 9, 2007, 3:59:22 PM2/9/07
to
if ("0123456789ABCDEFabcdef".IndexOf(c) >= 0)...

JR

"Luc E. Mistiaen" <luc.mi...@advalvas.be.no.spam> wrote in message
news:%23gdqBQG...@TK2MSFTNGP02.phx.gbl...

Luc E. Mistiaen

unread,
Feb 9, 2007, 11:35:16 PM2/9/07
to
if ("0123456789ABCDEF".IndexOf(char.ToUpper(c)) >= 0) :-)

/LM

"JR" <NoM...@qsm.co.il> wrote in message
news:uGuA90IT...@TK2MSFTNGP06.phx.gbl...

JR

unread,
Feb 10, 2007, 2:38:10 AM2/10/07
to
1. It is in general better to use ToLower rather than ToUpper, because of
the German small letter sharp S (Eszett) which translates to double S in
uppercase.

2. Although these days cycles to not matter much, converting the character
to uppercase is an expensive operation, locale dependent, and in this simple
case I think it would be better to add the lowercase letters to the string.

JR

"Luc E. Mistiaen" <luc.mi...@advalvas.be.no.spam> wrote in message

news:OEP%23dzMTH...@TK2MSFTNGP05.phx.gbl...

Jon Skeet [C# MVP]

unread,
Feb 10, 2007, 3:01:26 AM2/10/07
to
JR <NoM...@qsm.co.il> wrote:
> 1. It is in general better to use ToLower rather than ToUpper, because of
> the German small letter sharp S (Eszett) which translates to double S in
> uppercase.
>
> 2. Although these days cycles to not matter much, converting the character
> to uppercase is an expensive operation, locale dependent, and in this simple
> case I think it would be better to add the lowercase letters to the string.

Converting to lowercase is locale dependent as well. Personally I'd
just use

return (x >= '0' && x <= '9') ||
(x >= 'a' && x <= 'f') ||
(x >= 'A' && x <= 'F');

Simple and effective.

--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

0 new messages