-
Java Problem!!!
I have a question in Java. I am new to this language and i have a big(i think for me it is big) problem.
If i have a text file with a data record similar to the two lines of text shown below.
10000001 01.11.199600.00.000001 A1 1 SN
2001.11.200300096.0500072.0500081.65
and i want to pick up all the records whose first two digits are 10 (as
shown in the first example), what's the best way to do this ?
Cause its not possible to manually put a delimiter after the first two
digits in every single record and then scan the file for the first two
desired digits.
I want to know about the Java File handling mechanism.
Please reply.
Thank you very much.
-
In Psuedocode, it would be something like this (if I am understanding what you are trying to do)
loop:
Get fileName as a string.
create a new String s = fileName.substring(0,2).
see if s.matches ("[1][0]").
if it matches, then do action based on finding a valid filename.
Or you could do it this way:
Get fileName as a string.
Loop from 0 to 1
See if charat(0) is a 1, if true, then see if charat(1) is a 0.
If the chars match, then do action based on valid file name.
Does that help any??
-
I would use the regular expressions package, java.util.regex, construct a regular expression that matches the pattern of what you are looking for, then you split the results using a pattern.split() call and you have everything you need. For a full explanation of the java.util.regex package you can get it from the online api at http://java.sun.com/j2se/1.4.2/docs/api/index.html
-
I should have been more clear before, this package will do all of the work of a char at and all that and at the same time give you something that can possibly be reused.
-BigDick