Re: hi



Lab.Bhattacharjee@xxxxxxxxx wrote:
Hi kavitha,
u can try out the following code , it allows wild cards ,but is case
sensitive.Please tell me if u need that too??

The word is "you", not "u".

The trouble with doing someone's homework for them is that you deprive them of an education. That's a big waste of their tuition.

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RnD {

public static void main(String[] args) {

Please do not embed TABs in Usenet posts.

Pattern pattern = Pattern.compile("SAXELBY");

What is this regex? How did you come up with it? There was no indication in the OP for this.

BufferedReader reader = null;
try {
int lineNumber=0;
reader =
new BufferedReader(
new FileReader("C:\\00000001.txt"));

Hard-coded strings. Tsk, tsk. Where did you come up with it? There was no indication in the OP for this.

while (true) {

To depend on exceptions as flow control is a bad practice.

lineNumber++;
String curline = reader.readLine();
if (curline == null) {
break;
}
Matcher matcher = pattern.matcher(curline);
while (matcher.find()) {
System.out.println("at "+lineNumber+" "+
matcher.group()
+ " start="
+ matcher.start()
+ " end= "
+ matcher.end());
}
}

} catch (FileNotFoundException e) {
e.printStackTrace();

Ooh, you ignore the exception and move on. This is good for examples, bad in practice.

This is also a good place to introduce logging statements.

} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e1) {
e1.printStackTrace();

Those darn TABs.

}
}
}

}
}

- Lew
.



Relevant Pages

  • Re: hi
    ... BufferedReader reader = null; ... String curline = reader.readLine; ... Matcher matcher = pattern.matcher; ...
    (comp.lang.java.programmer)
  • Re: hi
    ... BufferedReader reader = null; ... String curline = reader.readLine; ... Matcher matcher = pattern.matcher; ...
    (comp.lang.java.programmer)
  • Re: Warships that blow up and why they fascinate
    ... reasonably interested reader of naval history. ... A testimony to the strict safety rules sailors tend to adhere to. ... And a clear indication of the navies where that did not happen. ...
    (sci.military.naval)
  • Re: SACD Player Recommendation
    ... meaning of the lines above withou any indication to the reader. ...
    (rec.audio.opinion)
  • Re: Three #include guards, which will never break?
    ... There is no indication that we are to remove the commenting in our ... The reader is expected to apply common sense. ...
    (comp.lang.c)