Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Character checking

 
Shakiran Williams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Shakiran Williams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 20894
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Shakiran Williams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic