How to check if a character in a string is a digit or letter
5 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Banketeshvar NarayanPosted Nov 13, 2015, 1:02 PM
Please accept my answer if it helps you.
gauss kadaPosted Nov 13, 2015, 1:00 PM
Banketeshvar NarayanPosted Nov 13, 2015, 12:55 PM
Complete code is
static void Main(string[] args)
{
string skypeId = "bnarayan123";
foreach (var c in skypeId.ToCharArray())
{
if (Char.IsLetter(c))
{
Console.WriteLine("{0} is letter", c);
}
else if (Char.IsDigit(c))
{
Console.WriteLine("{0} is digit", c);
}
}
}
Ravi PatelPosted Nov 13, 2015, 12:44 PM
Banketeshvar NarayanPosted Nov 13, 2015, 12:43 PM
Hi,
you can use
Char.IsLetter Method (Char)
Char.IsNumber Method (Char)
Char.IsLetterOrDigit Method
https://msdn.microsoft.com/en-us/library/yyxz6h5w%28v=vs.110%29.aspx
https://msdn.microsoft.com/en-us/library/yk2b3t2y%28v=vs.110%29.aspx
https://msdn.microsoft.com/en-us/library/system.char.isletterordigit%28v=vs.110%29.aspx
Please mark as answer if it helps you