File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Character checking Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Character checking" Watch "Character checking" New topic
Author

Character checking

Shakiran Williams
Greenhorn

Joined: Feb 13, 2006
Posts: 3
Hi, I have been at this all day and my brain has now turned to mush and I have a terrible headache so please go easy on me.

I need to check that a string has 9 characters and also check that it starts with a capital letter.

I just cannot get my head around starting this one, any pointers would be gratefully received. Thanks.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Hi,

Welcome to JavaRanch!

Well, as I see it, there are a number of steps here:

1) Getting ahold of the String in question;

2) Checking that it's 9 characters long;

3) Getting ahold of the String's 1st character;

4) Checking that it's uppercase; and

5) Reporting the result of the tests.

Let us know which of these parts you're having trouble with: show us your code so far. Let us know what documentation you've looked at -- in particular, do you know about the Javadoc API documentation? And finally, let us know what sort of hints you might need.
[ February 13, 2006: Message edited by: Ernest Friedman-Hill ]

[Jess in Action][AskingGoodQuestions]
Shakiran Williams
Greenhorn

Joined: Feb 13, 2006
Posts: 3
Hello again

Well, a new day has dawned and I shall try to give this another go.....positive thoughts.



Let us know which of these parts you're having trouble with:

2) Checking that it's 9 characters long;

3) Getting ahold of the String's 1st character;

4) Checking that it's uppercase;



Better get to it...thanks
[ February 14, 2006: Message edited by: Shakiran Williams ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19062
    
  40

Originally posted by Shakiran Williams:
Hello again

Well, a new day has dawned and I shall try to give this another go.....positive thoughts.

Better get to it...thanks


A good place to start is with the Javadoc for the String class. You can see that it does have methods that does exactly some of the things that you want to do.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Shakiran Williams
Greenhorn

Joined: Feb 13, 2006
Posts: 3
Thanks for the advice Henry.

Hello again

Well, i've been at this for days and i've tried everything (except the right thing of course) and still cannot come up with a code that checks it is 9 characters long and the first character is a capital letter.

The code below does run but i know its not right.



Other things i've tried:
if (data >= �A� && data <= �Z�),
i've tried charAt() but cannot get it all to fit together.

Any help at this point would be gratefully received. Thanks
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
data.length() == '9'

length() is the method you need - it returns an int,
but 9 is not the same as '9'
you are comparing it to a char, which has an int value - in this case 57

to check for upperCase, some other methods
charAt(), which returns a char
then, if you go to the Character class, you'll find a suitable method
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Character checking