How to find first index value in a string is character or numeric
-
Hi, how can i found that first index value in a string is char or numeric. Ex: if string is "CodeProject". I want to know first letter in a string "C" is character or numeric. can any one..give c# code for this. Ex: String str = "CodeProject";
G. Satish
-
Hi, how can i found that first index value in a string is char or numeric. Ex: if string is "CodeProject". I want to know first letter in a string "C" is character or numeric. can any one..give c# code for this. Ex: String str = "CodeProject";
G. Satish
public static bool IsFirstCharNumber(string str) {
if (string.IsNullOrEmpty(str))
return false;
int i = (int)str[0];
return (i < 58) && (i > 47);
}Petr Pechovic my latest articles: Web Page Loading in Steps - ASP.NET Solution[^] Buttons, Message Box and Confirm Box in ASP.NET 3.5[^]
-
Hi, how can i found that first index value in a string is char or numeric. Ex: if string is "CodeProject". I want to know first letter in a string "C" is character or numeric. can any one..give c# code for this. Ex: String str = "CodeProject";
G. Satish
-
public bool IsFirstCharDigit(string szYourstring)
{
if((szYourString != null) && (szYourString.Length > 0))
return char.IsDigit(szYourString.Chars(0));
return false;
}Greetings Covean
Thanks for the 1 vote! So I found an error in my code. But I think 1 is too hard!
public static bool IsFirstCharDigit(string szYourString)
{
if((szYourString != null) && (szYourString.Length > 0))
return char.IsDigit(szYourString[0]);
return false;
}or
public static bool IsFirstCharDigit(string szYourString)
{
if(!string.IsNullOrEmpty(szYourString))
return char.IsDigit(szYourString[0]);
return false;
}Greetings Covean