Results 1 to 4 of 4
  1. #1
    gutters is offline Member
    Join Date
    Jun 2008
    Posts
    2
    Rep Power
    0

    Default How to cut symbols from a string?

    For Example:
    I got a string with value "CatIsEatingDinner".
    I want to cut off the first 3 symbols and the last 6 so the remaining string would be "IsEating".

    How do I do that? I have searched the whole www for this...

  2. #2
    gutters is offline Member
    Join Date
    Jun 2008
    Posts
    2
    Rep Power
    0

    Default

    I'm that far:
    public String removeCharAt(String s, int pos) {
    return s.substring(0,pos)+s.substring(pos+1);
    }
    How do I make it to cut off the first 11 characters of the string?

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by gutters View Post
    For Example:
    I got a string with value "CatIsEatingDinner".
    I want to cut off the first 3 symbols and the last 6 so the remaining string would be "IsEating".

    How do I do that? I have searched the whole www for this...
    It's much easy to get a subString fro the original string. But in that case, the length of the cutting parts should be fix, at the time.

    Java Code:
            String str = "CatIsEatingDinner";
            int length = str.length();
            String temp = str.substring(3, (length - 6));
            System.out.println(temp);

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by gutters View Post
    I'm that far:
    public String removeCharAt(String s, int pos) {
    return s.substring(0,pos)+s.substring(pos+1);
    }
    How do I make it to cut off the first 11 characters of the string?
    What is the meaning of 11 characters, it's another requirement?

Similar Threads

  1. Replies: 2
    Last Post: 09-18-2008, 08:30 AM
  2. Replies: 0
    Last Post: 11-20-2007, 05:59 PM
  3. Replies: 1
    Last Post: 08-07-2007, 08:29 AM
  4. Replies: 1
    Last Post: 08-03-2007, 11:52 AM
  5. int and String, help me
    By lenny in forum New To Java
    Replies: 1
    Last Post: 07-24-2007, 01:14 PM

Posting Permissions

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