| Author |
Skip Line/Pattern with Scanner class
|
Viv Singh
Ranch Hand
Joined: Nov 08, 2008
Posts: 73
|
|
Hi,
I have the following content in a file:
Drives
********
cdr LITEON DVD-ROM LTD163 GDHA
cdr HL-DT-ST CD-RW GCE-8400B B104
My aim is to extract the information of both drives and I have written the following code:
I use s.nextLine() to skip the pattern *******, I tried to use the built in method skip as follows:
s.skip("*******");
but that did not work. Am I doing something wrong?
thanks in advance.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
* is part of regular expressions, so you will need to escape it with a \ (which again must be escaped because it is part of a string):
Of course, this can be shortened by using the count operator:
See Pattern for more information on regular expressions.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
 |
|
|
subject: Skip Line/Pattern with Scanner class
|
|
|