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: how to find second instance of char in string?

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

    Default how to find second instance of char in string?

    hi i am reading from a file and have a number of line like the following

    93.174.90.231:1005:nl Netherlands:4:00:00:14:check

    i want to split this line with a space or \n or anything at the second : but how can this be done i know there is replace() but this will only replace first instance or all but i need to leave the first instance in a nd remove/replace the others any help would be great thanks
    so should look like

    93.174.90.231:1005
    :nl Netherlands:4:00:00:14:check

    or similiar
    thanks
    Last edited by stac; March 12th, 2013 at 07:32 PM. Reason: gramer


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,094
    Thanks
    48
    Thanked 2,152 Times in 2,125 Posts

    Default Re: how to find second instance of char in string?

    Use the String class's method to find the first and then starting at its location find the next (the second one)
    Then use another String class method to get the sub parts of the String.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Get int value from char, char pulled from String
    By Andrew Red in forum What's Wrong With My Code?
    Replies: 3
    Last Post: February 4th, 2013, 09:04 AM
  2. Loop to find and replace multiple instances of a char
    By Olympaphibian89 in forum Loops & Control Statements
    Replies: 1
    Last Post: October 25th, 2012, 04:11 PM
  3. GUI program won't take 'char' input code, can't seem to find the correct one...
    By Eclecstatic in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 1st, 2012, 07:12 AM
  4. [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, 08:58 AM
  5. Address of String instance
    By American in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 6th, 2010, 02:20 PM