Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

character or digit

Status
Not open for further replies.

mm8294

MIS
Oct 12, 2001
73
US
My question is very simple: I have a string which is composed of three characters/digits, I need to know if the second character is a character ( AA6, etc. ) or a digit
( A6A, etc. ) ? I know this is pretty simple but I don't know how to do it. I am new to Java programming and I feel it is different to C.

Thank you very much for any help.
 
Hi,
U can use the following code
String str = "AA6";
if(Character.isDigit(str.charAt(1)))//pick the 2nd char
{
System.out.println("digit");
}
else if(Character.isLetter(str.charAt(1)))
{
System.out.println("character");
}

Hope this helps,
Reddy316.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top