473,473 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How can I know if a char is a Digit?


is there any function to know if a character is a Digit

Thanks in advantage...
Nov 15 '05 #1
4 2691
char.IsDigit()
-----Original Message-----
is there any function to know if a character is a Digit?

Thanks in advantage...
.

Nov 15 '05 #2
try this, it might not be the best solution but it works;

public bool IsInteger(Char theValue)
{
try
{
Convert.ToInt32(theValue);
return true;
}
catch
{
return false;
}
} //IsInteger

"Hector Martinez" <an*******@discussions.microsoft.com> wrote in message
news:B6**********************************@microsof t.com...


is there any function to know if a character is a Digit?
Thanks in advantage...

Nov 15 '05 #3
Marco Martin <ma**********@sympatico.ca> wrote:
try this, it might not be the best solution but it works;

public bool IsInteger(Char theValue)
{
try
{
Convert.ToInt32(theValue);
return true;
}
catch
{
return false;
}
} //IsInteger


No it doesn't - Convert.ToInt32(char) doesn't do what you think it
does. For instance, try this:

using System;
public class Test
{
static void Main()
{
Console.WriteLine (Convert.ToInt32('A'));
}
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
S***T! You're right. Sorry about that.

Marco
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Marco Martin <ma**********@sympatico.ca> wrote:
try this, it might not be the best solution but it works;

public bool IsInteger(Char theValue)
{
try
{
Convert.ToInt32(theValue);
return true;
}
catch
{
return false;
}
} //IsInteger


No it doesn't - Convert.ToInt32(char) doesn't do what you think it
does. For instance, try this:

using System;
public class Test
{
static void Main()
{
Console.WriteLine (Convert.ToInt32('A'));
}
}
--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #5

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

Similar topics

18
by: muser | last post by:
is string converted to its integer equivalent by minusing it by 48? the function is suppose to check the fifth digit of struct member using the formula contained within the function. The function...
6
by: John Smith | last post by:
What's wrong with the use of atoi in the following code? Why do I get the error message: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *' char cBuffer; void...
13
by: Nicholas | last post by:
How can I compare char* with integers and characters contained in the str, where integers can be one digit or more? void Access(char *str) { char *pt = str; while (pt != '0') { if...
9
by: | last post by:
void show( char *s, ...) is a function seemd like prinf code -------------- #include <stdio.h> #include <stdarg.h> void show( char *s, ...) { va_list stage;
5
by: Hector Martinez | last post by:
Is there any function to know if a char is a digit Thanks in advantage....
4
by: sophie | last post by:
Whats going on here: Read in a number as a string: scanf("%s", &number); number = 12345, for arguements sake Print it like this its fine:
5
by: rajus | last post by:
How to convert a char array to an int array?So if char s={"1234"}; then the int array say 'num' should have values num= 1 num=2 and so on.
80
by: Gaijinco | last post by:
Is there an elegant way to do something like // given a char {0,1,2,3,4,5,6,7,8,9} returns it as a short short char2digit(char c) { short d = c-48; return d; } ?
13
by: Mantorok | last post by:
Hi Is it possible to convert 2 char values to an integer and be able to reverse it? I'm sure there must be some algorithm to achive this. Any ideas? Thanks Kev
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.