Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: I can't get useDelimiter to cooperate

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    1
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default I can't get useDelimiter to cooperate

    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?


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: I can't get useDelimiter to cooperate

    Please provide more information on your project (preferably an SSCCE), as we can only guess what the useDelimiter method refers to. I'm in a guessing mood so I'll take a shot: you are referring to the Scanner method useDelimiter, in which case this is the delimiter. If you wish to capture groups and have more fine tuned parsing, I recommend reading Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes). You could also use the methods of the String class to accomplish a same task

  3. The Following User Says Thank You to copeg For This Useful Post:

    Loo (December 9th, 2013)

Similar Threads

  1. how to use Scanner and useDelimiter with int
    By scdesign in forum Java Theory & Questions
    Replies: 9
    Last Post: August 30th, 2013, 04:23 AM
  2. Scanner.useDelimiter("\n") Problem
    By Noob_Programmer in forum What's Wrong With My Code?
    Replies: 6
    Last Post: July 31st, 2011, 09:28 AM

Tags for this Thread