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

Thread: Setting markers in strings??

  1. #1
    Junior Member
    Join Date
    Dec 2009
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Smile Setting markers in strings??

    Hi all,

    I'm having a bit of trouble on a bit of code I'm working on.

    Basically I'm writing a method where the user enters a String, then a letter within that string as marker 'a', then another as marker 'b'.

    The method then neds to output the text between those markers.

    For example if the user enters "hello to everyone", "o ", y"

    it will output "every"

    so basically it outputs the first marker letter, then all the letters after it up to and including the second marker.

    It should be an easy task but for some reason I'm having real trouble with it.

    Any ideas??

    Thanks in advance

    John


  2. #2
    Junior Member
    Join Date
    Dec 2009
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Setting markers in strings??

    Anyone??

  3. #3
    Member
    Join Date
    Feb 2010
    Location
    Auburn, AL
    Posts
    31
    Thanks
    0
    Thanked 8 Times in 8 Posts

    Default Re: Setting markers in strings??

    First of all, if it's supposed to get the text between the first occurrence of the first marker and the first occurrence of the second marker, inclusive, then in your example,

    hello to everyone

    the output would actually be "o to every". Is this correct?

    In that case, just find the first occurrence of the first marker, the first occurrence of the second marker, and then use the substring function with the appropriate indices. Some pseudocode...

    FindMarked(source: string, marker1: character, marker2: character)
    1. index1 := FindFirst(source, marker1)
    2. index2 := FindFirst(source, marker2)
    3. return source[index1...index2]
     
    FindFirst(source: string, marker: character)
    1. for i := 1 to len(source)
    2.    do if source[i] = marker then return i
    3. return 0
    Let me know what you think of my website:
    http://www.auburn.edu/~carpept
    Comments or suggestions are appreciated!

  4. The Following User Says Thank You to CT&SC For This Useful Post:

    wingchunjohn (February 20th, 2010)

  5. #4
    Junior Member
    Join Date
    Dec 2009
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Setting markers in strings??

    Hi there,

    Thanks for taking time to give me some advice.

    Yes you are right about what should be outputted!! Thanks

    You have helped me loads with this. I owe you one!!

    Thanks for your time & advice

    - John
    Last edited by wingchunjohn; February 20th, 2010 at 05:40 AM.

Similar Threads

  1. setting the compiler for eclipse mac os x
    By etidd in forum Java IDEs
    Replies: 2
    Last Post: January 29th, 2010, 10:18 AM
  2. Strings
    By Leeds_Champion in forum Algorithms & Recursion
    Replies: 3
    Last Post: November 3rd, 2009, 10:09 PM
  3. Strings
    By BeSwift21 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 13th, 2009, 08:02 PM
  4. Problems in setting classpath
    By missyati in forum Java Theory & Questions
    Replies: 3
    Last Post: June 30th, 2009, 01:43 AM
  5. Replies: 2
    Last Post: June 19th, 2008, 04:58 AM