IsDigit( ) and IsSymbol( ) function in C# [modifed]
-
Hi all, I want to know that are there any functions like IsDigit and IsSymbol in C# wich let us know that any particular string contains any numbers or puncuation symbols....if they exist then wich r they.....and if they dont then how can we achieve this Looking forward for help Regards, -- modified at 4:37 Saturday 20th May, 2006
-
Hi all, I want to know that are there any functions like IsDigit and IsSymbol in C# wich let us know that any particular string contains any numbers or puncuation symbols....if they exist then wich r they.....and if they dont then how can we achieve this Looking forward for help Regards, -- modified at 4:37 Saturday 20th May, 2006
Char.IsDigit, etc, work on a per char basis. I believe there are string based functions, but I have not found them as static methods on string. You can of course use int.TryParse and double.TryParse to see if the value is an int or a double, respectively. Christian Graus - Microsoft MVP - C++ -- modified at 4:47 Saturday 20th May, 2006
-
Hi all, I want to know that are there any functions like IsDigit and IsSymbol in C# wich let us know that any particular string contains any numbers or puncuation symbols....if they exist then wich r they.....and if they dont then how can we achieve this Looking forward for help Regards, -- modified at 4:37 Saturday 20th May, 2006
Hi, I dont know about whether there is any in built function for your problem but you can implement this logic in your program by parsing the string character by character and knowing the ASCII codes for them. then compare the ascii codes for each character to be in range of for example numbers, characters or symbols. For this you will have to know the code ranges for numbers, symbols and alphabets in ASCII. And for inbuilt functions try searching the msdn or msdn online at - http://mdsn.microsoft.com/library A simple logic would be to convert the string into char[] and then loop in this array to check for Char.IsDigit and Char.IsNumber and Char.IsSymbol, etc.... (I found this after posting the message, so i modified the last post) Anant Y. Kulkarni -- modified at 4:45 Saturday 20th May, 2006
-
Hi, I dont know about whether there is any in built function for your problem but you can implement this logic in your program by parsing the string character by character and knowing the ASCII codes for them. then compare the ascii codes for each character to be in range of for example numbers, characters or symbols. For this you will have to know the code ranges for numbers, symbols and alphabets in ASCII. And for inbuilt functions try searching the msdn or msdn online at - http://mdsn.microsoft.com/library A simple logic would be to convert the string into char[] and then loop in this array to check for Char.IsDigit and Char.IsNumber and Char.IsSymbol, etc.... (I found this after posting the message, so i modified the last post) Anant Y. Kulkarni -- modified at 4:45 Saturday 20th May, 2006
You should NEVER do this. You can use foreach on a string and use Char.IsDigit ( for example ). Using ASCII codes and assuming they are valid is a bad idea on a number of levels. Christian Graus - Microsoft MVP - C++
-
You should NEVER do this. You can use foreach on a string and use Char.IsDigit ( for example ). Using ASCII codes and assuming they are valid is a bad idea on a number of levels. Christian Graus - Microsoft MVP - C++
Hi, I havent got your point. Is there any way that the ASCII codes may be wrong? I think as you press the keys the ASCII codes are stored or sent to the program or what ever. but main point is ASCII is used for representing the characters. Means we used to do this in C. Is there any issues related to using ASCII values for comparisions. If yes, i would be greatfull to know. Also can you please elaborate on the point you replied to my post.
Christian Graus wrote:
Using ASCII codes and assuming they are valid is a bad idea on a number of levels.
Number of levels? I hope you got my point. Thanks Anant Y. Kulkarni
-
Hi, I havent got your point. Is there any way that the ASCII codes may be wrong? I think as you press the keys the ASCII codes are stored or sent to the program or what ever. but main point is ASCII is used for representing the characters. Means we used to do this in C. Is there any issues related to using ASCII values for comparisions. If yes, i would be greatfull to know. Also can you please elaborate on the point you replied to my post.
Christian Graus wrote:
Using ASCII codes and assuming they are valid is a bad idea on a number of levels.
Number of levels? I hope you got my point. Thanks Anant Y. Kulkarni
Anant Kulkarni wrote:
Is there any way that the ASCII codes may be wrong?
Well, for starters, they could be unicode codes. .NET is unicode by default.
Anant Kulkarni wrote:
Means we used to do this in C.
Yep, I did it in C from time to time, although mostly I'd use the functions built in there, too.
Anant Kulkarni wrote:
Number of levels?
As well as the Unicode issue, it's just a hack when the language provides stuff like Char.IsDigit. Christian Graus - Microsoft MVP - C++
-
You should NEVER do this. You can use foreach on a string and use Char.IsDigit ( for example ). Using ASCII codes and assuming they are valid is a bad idea on a number of levels. Christian Graus - Microsoft MVP - C++
Sir i have tried to do this in this way
foreach(char ch in docName.ToCharArray())
{
if(ch.IsDigit())
break;
}but the problem is that this IsDigit and other r static methods so how can i access them :( looking forward for help Regards,
-
Sir i have tried to do this in this way
foreach(char ch in docName.ToCharArray())
{
if(ch.IsDigit())
break;
}but the problem is that this IsDigit and other r static methods so how can i access them :( looking forward for help Regards,
As it's a static method, you call it as I demonstrated, using the class name if (Char.IsDigit(ch)) break; Christian Graus - Microsoft MVP - C++
-
As it's a static method, you call it as I demonstrated, using the class name if (Char.IsDigit(ch)) break; Christian Graus - Microsoft MVP - C++
Thxx Sir, its working :)