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 3 of 3

Thread: Help capture part of a string please :)

  1. #1
    Member
    Join Date
    Nov 2009
    Posts
    57
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Help capture part of a string please :)

    I have the following string (the parts between the double quotes is dynamic so not the same length or content each time) and I need to pick out who is logged on only, don't need any of the other content.

    "explorer.exe","2012","Console","1","30,832 K","Running","MYDOMAIN\Administrator","0:00:02","N/A"


    Now, I need to get the MYDOMAIN\Administrator part only (not including the quotes) and keep this in a variable.

    Could someone help me out with this, i'm sure it is fairly easy for one of you regex experts to do.

    Thank you.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Help capture part of a string please :)

    I'm not fluent in regex, so I avoid it more than I should. Even so, if the number of items is the same and they're always in the same order, then I'd use String.split() to obtain the 7th item in the String you posted and go from there.

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

    mds1256 (September 23rd, 2013)

  4. #3
    Member
    Join Date
    Nov 2009
    Posts
    57
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default Re: Help capture part of a string please :)

    Perfect! an excellent way to provide a simple solution to a complex problem

    String test = "\"explorer.exe\",\"2012\",\"Console\",\"1\",\"30,832 K\",\"Running\",\"MYDOMAIN\\Administrator\",\"0:00:02\",\"N/A\"";
            String[] parts = test.split("\",\"");
            String part = parts[6];
            System.out.println(part);

    Thank you again, this has helped me out.

Similar Threads

  1. Replies: 3
    Last Post: October 26th, 2012, 02:19 PM
  2. Draw and arc under part of a string
    By lammybun in forum Java Theory & Questions
    Replies: 3
    Last Post: February 26th, 2012, 12:26 PM
  3. How to find a a certain part in string
    By redzero36 in forum Java Theory & Questions
    Replies: 7
    Last Post: July 19th, 2011, 06:39 PM
  4. How to capture standard output from another program ?
    By ni4ni in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 3rd, 2010, 11:00 AM
  5. Java program for remote host screen capture
    By krishnaraoveera1294 in forum Java Networking
    Replies: 1
    Last Post: March 13th, 2009, 04:53 AM