Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do you test a String for all alpha characters

Posted on 2003-10-23
4
Medium Priority
?
400 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This video teaches viewers about errors in exception handling.
Suggested Courses

824 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