On Sat, 26 Jul 2003 17:12:35 GMT, Brett <magnesium_@yahoo.com> wrote
or quoted :
>I am working on a program where I need to check a very short string to
>see if it is either one or two digits. Specifically I need to check if
>there is a second digit or not.
> I have tried:
>if ( isNull(string someString.charAt(1)) )
>if ( string someString.charAt(1) == null )
>if ( isNaN(string someString.charAt(1)) )
>if ( string someString.length < 2 )
Your syntax is quite imaginative. Usually for something like this you
can find an example in a text book or online tutorial.
if ( something == null || something.length() < 2 )
Your attempts indicate you have quite a few misconceptions about Java.
1. you can't just make up method names. They must be defined, or you
must write them, e.g. isNull
2. String is a class and must always be specified by a capital letter.
3. when defining a variable a you mention its class, e.g. String, but
you may not when you reference it, e.g. in an IF statement.
4. the notion of NaN applies only to floating point numbers, not
Strings. See
http://mindprod.com/jgloss/floatingpoint.html
5. charAt treats the String as a char[]. If you go out of bounds you
get an exception, not a null result.
6. In Java sometimes you write length and sometimes you write
length(), and sometimes size(). This is done to haze newbies and
boost billable hours correcting the errors.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See
http://mindprod.com/jgloss/jgloss.html for The Java Glossary.