• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Old COBOL dude needs direction

 
Bob Gidlow
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9066
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

 
Bob Gidlow
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I have located my problem, I was "off by 1" in my logic,
this can be closed now
 
Cindy Glass
"The Hood"
Sheriff
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nah, we never close them. Who knows when someone new might come along and have some profound thing to say about this topic .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic