aspose file tools*
The moose likes Beginning Java and the fly likes Old COBOL dude needs direction Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Old COBOL dude needs direction" Watch "Old COBOL dude needs direction" New topic
Author

Old COBOL dude needs direction

Bob Gidlow
Greenhorn

Joined: Jul 20, 2001
Posts: 2
Is there a way to check if a character is alphanumeric. I was trying the code below but am picking up "all" characters. The string of data that I am checking should only have an alphanumeric in a particular position. I have the position part down pat but not the check. Did I need to "create" an alphanumeric table to compare. Thanks
/**
* Returns True if given String contains only numeric characters,
* otherwise returns False
*/
private boolean isNumeric(String newString)
{
char[] chars = newString.toCharArray();
Character c;
for (int x = 0; x < chars.length; x++)
{
if (!Character.isDigit(chars[x]))
{
return false;
}
}
return true;
}
/**
* Returns True if given String contains an alphanumeric,
* otherwise returns False
*/
public boolean isLetterOrDigit(String newString)
{
if ((newString == null) | | (newString.length()==0))
return false;
char[] chars = newString.toCharArray();
for (int x = 0; x < chars.length; x++)
{
if (!Character.isLetterOrDigit (chars [x]))
{
return false;
}
}
return true;
}//end method
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Bob Gidlow
Greenhorn

Joined: Jul 20, 2001
Posts: 2
Thanks, I have located my problem, I was "off by 1" in my logic,
this can be closed now
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Nah, we never close them. Who knows when someone new might come along and have some profound thing to say about this topic .


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
wood burning stoves
 
subject: Old COBOL dude needs direction