This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Skip Line/Pattern with Scanner class  RSS feed

 
Viv Singh
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 21044
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
* 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!