8 Replies - 4216 Views - Last Post: 21 January 2006 - 11:08 AM Rate Topic: -----

#1 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

is a character a capital

Posted 19 January 2006 - 05:39 PM

I'm new to java, and I'm wondering if there's a function already built into java that would tell me if a letter is a captial letter...
Is This A Good Question/Topic? 0
  • +

Replies To: is a character a capital

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: is a character a capital

Posted 19 January 2006 - 06:16 PM

I don't believe so...but you should be able to check the ASCII value of the character in question.
Was This Post Helpful? 0
  • +
  • -

#3 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: is a character a capital

Posted 19 January 2006 - 06:33 PM

I'm working with this currently,

(character < 'A') || (character > 'Z')



in an if statement of course, because i think that implies that it's not between A and Z...i'll let you know if it works, or rather, i'll be back to ask more questions if it doesn't work ;)
Was This Post Helpful? 0
  • +
  • -

#4 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4517
  • View blog
  • Posts: 28,417
  • Joined: 21-March 01

Re: is a character a capital

Posted 19 January 2006 - 07:20 PM

it should be greater than or equal to A and less than or equal to Z. capital letters are ascii values 65 to 90, as it stands now your code tests for everything that isn't a capital. (ie less than 65 and greater than 90)
Was This Post Helpful? 0
  • +
  • -

#5 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: is a character a capital

Posted 20 January 2006 - 10:16 AM

it actually turns out that i needed to know if a letter wasn't a capital so what i had works for me :)

thanks for all your guys help ;)
Was This Post Helpful? 0
  • +
  • -

#6 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: is a character a capital

Posted 21 January 2006 - 04:18 AM

STOOOOOOOOOOOP!!!!!!!!!!!!!!!!

DO NOT DO THAT!
It works for ASCII letters only! It might be good for an assignment(sadly), but please, DO NOT DO IT THAT WAY! It was good back in the old C days, and worked fine. But now people from all over the world would like to use your application, and they can be very disappointed if doesn't behave as expected and produces strange things for letters outside the ASCII table.
Java uses Unicode, so take advantage of it! It knows if a character is a letter, or if it is uppercase, or not.

So the answer for the original question, you need the following, from the Character class (all static methods, so an instance is not required):

boolean Character.isLetter(char ch) - tells you if its a letter, you might get away without using this...
boolean Character.isLowerCase(char ch) returns true, if its not capital
boolean Character.isUpperCase(char ch) returns true, if its a capital

That's it, and PLEASE think about the guys who don't use English in their everyday life, thank you!

This post has been edited by 1lacca: 21 January 2006 - 04:21 AM

Was This Post Helpful? 0
  • +
  • -

#7 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: is a character a capital

Posted 21 January 2006 - 07:11 AM

Thanks, 1lacca! Good post...I had been aware of the isLetter method, but not the upper and lower case tests...God, I must be getting older...things are escaping me! :)
Was This Post Helpful? 0
  • +
  • -

#8 1lacca  Icon User is offline

  • code.rascal
  • member icon

Reputation: 44
  • View blog
  • Posts: 3,822
  • Joined: 11-August 05

Re: is a character a capital

Posted 21 January 2006 - 07:28 AM

Lol, you are welcome.
I have seen so many applications stumbling on the problem of encoding. I was happy to see Java solving this problem so nicely, kindly forcing developers into using unicode (and taking advanteges of its features), so that's why I was triggered by this thread :)
Was This Post Helpful? 0
  • +
  • -

#9 fyrestorm  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 10
  • View blog
  • Posts: 3,113
  • Joined: 04-April 02

Re: is a character a capital

Posted 21 January 2006 - 11:08 AM

sweetness, thanks 1lacca, that's what i was looking for...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1