Results 1 to 3 of 3
Like Tree1Likes
  • 1 Post By Fubarable

Thread: Remove part of a string

  1. #1
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Remove part of a string

    For example if I have a string like:

    Java Code:
    String str = "hello 4235 blah blah\nhello2 4353242 blah blah\n"; ... etc
    How can I remove the first line? For example remove everything until a '\n' and then remove the '\n'.

    By the way:
    The Strings always change so I can't do str.replace("hello 4235 blah blah\n", "");
    Last edited by PhQ; 09-17-2011 at 12:35 AM.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Remove part of a string

    You could split the String on "\\n" and then take the parts you desire, you could use subString after finding the location of the next \n with indexOf.
    PhQ likes this.

  3. #3
    PhQ's Avatar
    PhQ
    PhQ is offline Senior Member
    Join Date
    Mar 2010
    Location
    Lithuania
    Posts
    358
    Rep Power
    5

    Default Re: Remove part of a string

    Quote Originally Posted by Fubarable View Post
    You could split the String on "\\n" and then take the parts you desire, you could use subString after finding the location of the next \n with indexOf.
    Ahh.. I'm so stupid.
    Thank you.
    Never thought it could be this easy.

    I should of looked at the api. :P

Similar Threads

  1. Split string and remove
    By drogba123 in forum New To Java
    Replies: 2
    Last Post: 03-20-2011, 11:52 AM
  2. Replies: 9
    Last Post: 04-23-2010, 02:52 AM
  3. unicode as part of string
    By mac in forum New To Java
    Replies: 0
    Last Post: 01-28-2010, 03:23 AM
  4. search with part of string
    By virendra in forum Lucene
    Replies: 1
    Last Post: 01-21-2010, 01:56 PM
  5. How to get part of a String?
    By eva in forum New To Java
    Replies: 1
    Last Post: 12-23-2007, 07:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •