Solved

How do you test a String for all alpha characters

Posted on 2003-10-23
4
391 Views
Last Modified: 2010-05-18
How do you test a String for all alpha characters, or all numeric characters returning a bool?
0
Comment
Question by:rayskelton
  • 3
4 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 9606184
 public static String allAlpha(String s) {
      StringBuffer sb = new StringBuffer(s);
      for(int i = 0;i < sb.length();i++) {
        if(Character.isAlphaChar(sb.charAt(i)) == false)
            return false;
      }
      return true;
  }

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9606194
isAlphaChar

should be

isLetter
0
 

Author Comment

by:rayskelton
ID: 9606520
Perfect, I changed the return to boolean.

Thanks
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 9608054
>>I changed the return to boolean.

D'oh, another error ;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now