Hi. I am rather new to java and am stuck on something that seems like it should be easy. I am reading in several lines/records from a text file into a buffer. Each line is about 80 characters, however, the first 20 characters make up field1. Thus, I used a substring (0,19) on the line to get field1 formy object test:
test.field1 = line.substring(0,19)
This seems to be working ok. The problem I have is that within the 20 characters of field1, there might really be less than 20 characters/numbers (actually this is the case more often than not) and the field is made up of a mix of letters and numbers. For example, "98A" "203456TTYCLOV" "1234567891" "bb22bb" could all be field1. I am now trying to find all the field1 where it is exactly 10 numbers ...no letters, no more than 10 numbers, etc, such as "1231231234"
First step, I need to determine that the length is actually just 10 (then I will figure out whether they are letters or numbers, etc). To find the actual length.....
If tried the length method, I always get 20 regardless, even if the last 10 "spaces" are empty.
So, then I tried to find if the eleventh character (really the 10th position) is null, and that just gave me error message after error message regardless of what I tried. Next, I tried to set up a method checkNum which would return true or false. Within this method, I set up another substring on field1which pulls in everything from the 11th character on...
String eleventhOn = this.field1.substring(10,19)
I then went to compare whether this string eleventhOn was empty/null and if so, return True. However, it never seems to find a positive comparison. It always returns false, though I know there are instances where evelenthOn is empty...I even have it printing the string out on the screen and sure enough, there are times when it prints blanks, so I know I am getting the right substring. I have tried various operators, including ==null, equals(""), etc, but I cannot seem to get it to work (no error messages, it just doesn't seem to recognize when the last 10 slots are blank)
Any help would be great! Thanks
And, if you could also tell me how on earth to compare a char, I would really appreciate it (and can award more points..as I am sure I will need that comparison too). Thanks!
FYI- right now, I am only concerned w/fields that are greater than 10, and not worried about the ones less than.