• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Old COBOL dude needs direction

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

 
Bob Gidlow
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, I have located my problem, I was "off by 1" in my logic,
this can be closed now
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
I will suppress my every urge. But not this shameless plug:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic