I am trying to make my program read a token from a string, and print out an error if the token contains invalid characters, ie smit4h.
I have this....
which seems to work, although i dont really understand how I got here.
Is there a better way to complete this??
EDIT: Another item in the program is puzzling me also.
If a date string in the program is too long or short, format(dd-mm-yy) another error is printed.
works by itself, but if i put it in the main program, as a method, it prints out all dates as errors, regardless of if they are wrong or not. Any ideas? [ March 26, 2006: Message edited by: Paul Andrew ]
Note also the important point that Garrett has used "myCharArray.length" instead of '53'. Using numbers like 53 is bad for all kinds of reasons; one reason is that figuring them out in the first place is extra work. A more important reason is that if the code ever must change, finding every instance of '53' may be hard to do. Better to use a variable containing the value, or compute the value as needed, the way it's been done here.
You can try Regular expression (if your JDK > 1.4) like:
[ March 26, 2006: Message edited by: Mahadevan Gorti SS ] [ March 27, 2006: Message edited by: Mahadevan Gorti SS ]
Joined: Jan 17, 2006
Originally posted by Paul Andrew: Great, thanks for the help guys, the code looks better already. I have just one little thing to add to this, say i also had to allow commas to be classed as valid, which commands would to this.
if (!Character.isLetter(array1[i])) || ,
point noted about the variables, it was annoying to type in the letters
[ March 26, 2006: Message edited by: Paul Andrew ]