File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

I can't get useDelimiter to cooperate

 
Luke Heenan
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a Java project and I am trying to get useDelimiter to remove everything except the text in between "=" and ",". For example, on the first line of the file I would like to keep "ThermostatNight".

This is what the text file looks like:

Event=ThermostatNight,time=0

Event=LightOn,time=2000


I've been able to do the exact opposite using this code:

s.useDelimiter("=(.*?),");

Is there any way I can tweak this to do the opposite?

Edit: The "s" is a scanner.
 
Krishna Kanth
Ranch Hand
Posts: 49
1
Chrome Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the actual output you are looking for, with above data?
 
Winston Gutkowski
Bartender
Pie
Posts: 9462
49
Eclipse IDE Hibernate Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Luke Heenan wrote:I am working on a Java project and I am trying to get useDelimiter to remove everything except the text in between "=" and ",". For example, on the first line of the file I would like to keep "ThermostatNight".

Why useDelimiter? That sounds like you've decided HOW to do it, before you've decided WHAT you want to do, which is almost always a bad methodology.

So: WHAT do you want to do? And explain in English, not Java.

However, just as a kick-start, you might look want to look at String.indexOf().

Winston
 
Luke Heenan
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This ended up working:

s.useDelimiter("Event=|,(.)+[\\r\\n]*Event=|,(.)+[\\r\\n]*");
 
Campbell Ritchie
Sheriff
Pie
Posts: 47229
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done, and welcome to the Ranch

There are probably more elegant ways to divide that text than useDelimiter. Try indexOf("=") and substring() and similar, as Winston has already told you.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic