PDA

Click to See Complete Forum and Search --> : [RESOLVED]Retrieve product number from SDF file


huiling25
Jan 22nd, 2007, 12:15 AM
I have a sdf file, i wan to retrieve product numbers from the file. However, when i print out, it only printed out the first product number(02230416222D). There are supposed to be 2 products numbers, does anyone knows why my program only loop 1 time?
This is how the sdf file looks like:


-ISIS- 02230416222D

17 18 0 0 0 0 0 0 0 0999 V2000

......
$$$$//this is end of the first product
-ISIS- 02230416222D

17 18 0 0 0 0 0 0 0 0999 V2000
......
$$$$ //this is the end of second product


This is my java program:

Scanner inFile = new Scanner(new FileReader("merlin3.sdf"));
while(inFile.hasNext("-ISIS-"))
{
String line = inFile.nextLine();
String pdt = line.replaceAll("-ISIS-","");
String pdtNo = pdt.trim();
System.out.println(pdtNo);
}

huiling25
Jan 22nd, 2007, 03:29 AM
Here is the solution:
while(inFile.hasNext()) {
String line = inFile.nextLine();
if(line.contains("-ISIS-")) {
String pdt = line.replaceAll("-ISIS-","");
String pdtNo = pdt.trim();
System.out.println(pdtNo);
}
}