2 Replies - 26254 Views - Last Post: 29 April 2009 - 07:09 PM Rate Topic: -----

#1 bandwand  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 26-April 09

Java equivalent for C's isAlpha?

Post icon  Posted 28 April 2009 - 05:43 PM

public boolean isValidStart(char c) {
		switch (c) {
		case 'a':
		case 'b':
		case 'c':
		case 'd':
		case 'e':
		case 'f':
		case 'g':
		case 'h':
		case 'i':
		case 'j':
		case 'k':
		case 'l':
		case 'm':
		case 'n':
		case 'o':
		case 'p':
		case 'q':
		case 'r':
		case 's':
		case 't':
		case 'u':
		case 'v':
		case 'w':
		case 'x':
		case 'y':
		case 'z':
		case 'A':
		case 'B':
		case 'C':
		case 'D':
		case 'E':
		case 'F':
		case 'G':
		case 'H':
		case 'I':
		case 'J':
		case 'K':
		case 'L':
		case 'M':
		case 'N':
		case 'O':
		case 'P':
		case 'Q':
		case 'R':
		case 'S':
		case 'T':
		case 'U':
		case 'V':
		case 'W':
		case 'X':
		case 'Y':
		case 'Z':
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
		case '0':
			return true;
		case '?':
			return false;
		default:
			return false;
		}
	}


Is there an better way to do this in Java?
Thanks!

Is This A Good Question/Topic? 0
  • +

#3 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: Java equivalent for C's isAlpha?

Posted 28 April 2009 - 05:49 PM

Character's isDigit()

Character's isLetter()
Was This Post Helpful? 1

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Java equivalent for C's isAlpha?

Posted 29 April 2009 - 07:09 PM

Wouldn't have definitively qualified this post as "Intermediate" :)

even in C

if(c >= 'a' && c <= 'z')
   return true;
if(c >= 'A' && c <= 'Z')
   return true;
return false;


This post has been edited by pbl: 29 April 2009 - 07:11 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1