File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes I can't get useDelimiter to cooperate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I can Watch "I can New topic
Author

I can't get useDelimiter to cooperate

Luke Heenan
Greenhorn

Joined: Dec 08, 2013
Posts: 2
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

Joined: Oct 23, 2006
Posts: 49
    
    1

What is the actual output you are looking for, with above data?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 8049
    
  22

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

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Luke Heenan
Greenhorn

Joined: Dec 08, 2013
Posts: 2
This ended up working:

s.useDelimiter("Event=|,(.)+[\\r\\n]*Event=|,(.)+[\\r\\n]*");
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
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.
 
Consider Paul's rocket mass heater.
 
subject: I can't get useDelimiter to cooperate