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: Looking at a string ...

  1. #1
    Junior Member
    Join Date
    Oct 2010
    Posts
    27
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Looking at a string ...

    Hey guys - quick question.

    I'm writing a little program just for the fun of it, and to start off I'm having the user enter a string - the string will be inputted in the same format but there will be different numbers in the spots.

    I need to go through the string and when it comes upon the group of characters that will always match, I need it to pull the variable out. For example, the string will always have the format "This is x and this is y" - but x and y will change. So when it goes through the string and comes upon "and" it should go back and grab the x value.

    Any ideas?

    Thanks


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Looking at a string ...

    Quote Originally Posted by joshft91 View Post
    but there will be different numbers in the spots.
    If you mean the input will be like:

    This is 2 and this is 2564
    This is 42 and this is 12

    then you can use the Pattern and Matcher classes.

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Looking at a string ...

    Look up 'Regular Expressions'. This is a good place to start:

    Lesson: Regular Expressions (The Java™ Tutorials > Essential Classes)

Similar Threads

  1. private Map<String, ArrayList> xlist = new HashMap<String, ArrayList>();
    By Scotty in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 21st, 2011, 08:37 AM
  2. Replies: 18
    Last Post: March 2nd, 2011, 10:52 AM
  3. [SOLVED] String Matcher finding only char not a whole string
    By Kakashi in forum What's Wrong With My Code?
    Replies: 11
    Last Post: February 18th, 2011, 09:58 AM
  4. Replies: 2
    Last Post: December 22nd, 2010, 09:21 AM
  5. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM