posted 12 years ago
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.
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.
posted 12 years ago
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 ]
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
posted 12 years ago
Hello again
Well, a new day has dawned and I shall try to give this another go.....positive thoughts.
Better get to it...thanks
[ February 14, 2006: Message edited by: Shakiran Williams ]
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 ]
posted 12 years ago
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
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
posted 12 years ago
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
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
posted 12 years ago
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
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
