Solved

How do you test a String for all alpha characters

Posted on 2003-10-23
4
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Suggested Courses

622 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