473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

IsDigit...

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
Nov 15 '05 #1
7 9468
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
Nov 15 '05 #2
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

Nov 15 '05 #3
Per Rollvang wrote:
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>
Nov 15 '05 #4
Per Rollvang wrote:
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)
Nov 15 '05 #5
Per Rollvang <pe**********@chello.no> wrote:
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 - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP***********************@msnews.microsoft.co m...
Per Rollvang <pe**********@chello.no> wrote:
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 - <sk***@pobox.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
Nov 15 '05 #7
"Frank Oquendo" <fr****@acadxpin.com> wrote in message
news:eo**************@TK2MSFTNGP09.phx.gbl...
Per Rollvang wrote:
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)


Thanks Frank, it worked like a charm...

-Per

Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: James Gregory | last post by:
I read that the argument to isdigit() can be "an integer whose value is representable as an unsigned char, or the value of the macro EOF.". This seems to say that it should work for values greater...
15
by: Carramba | last post by:
hi! I am trying to confirm if input is digit, so I thought it would by easy to do it with with isdigit() funktion, but how do I pass arrays to it if the imput is more then 1 sign? #include...
2
by: Jefe | last post by:
Hi Group Could you please explain to me what's the difference between Chars.IsDigit and Chars.IsNumber? Regards,
10
by: mdh | last post by:
Could I get some help as to understanding why I am not getting a result I expect. #include <stdio.h> #include <ctype.h> int main (){ int i,j,k,c; i=9;
16
by: skneife | last post by:
Doeas any know the simplest way for create this type of function: bool result = IsDigit(string s); Sam
3
by: MooMaster | last post by:
N00b question alert! I did a search for isdigit() in the group discussion, and it didn't look like the question had been asked in the first 2 pages, so sorry if it was... The manual...
2
by: bozo789 | last post by:
Hi Forum, First let me begin by stating I am a student and have read the proper posting procedure concerning students. I am a begginer learning with the Miracle C Work Bench. I know my code is...
1
by: khaichiew85 | last post by:
im having a program.I want it to check if it is a character or integer is entered where shall i put the isDigit and how to use?i put it as highlighted below but got error. #include<stdio.h>...
0
by: Parth Gallen | last post by:
Character.isDigit() or Character.isLetter() in Java.lang work of course, but I had to make my own solution as homework so here they are: isDigit method: static boolean isDigit(char c) {...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.