Results 1 to 10 of 10
  1. #1
    hacikho is offline Member
    Join Date
    Sep 2009
    Posts
    35
    Rep Power
    0

    Default Getting substring ???

    I have a string, String mystring="ABCD";
    I want to produce four more string from above string such as "BCD", "ACD", "ABD", "ABC", how is this possible, can you give me some logic, idea. This is not a certain string it might be very long or shor, characters could be anything.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: Getting substring ???

    Recursion and loops.

  3. #3
    hacikho is offline Member
    Join Date
    Sep 2009
    Posts
    35
    Rep Power
    0

    Default Re: Getting substring ???

    I just start thinking of it, but I stucked at how to remove ith character, or delete?

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: Getting substring ???

    That is a statement not a question.

  5. #5
    hacikho is offline Member
    Join Date
    Sep 2009
    Posts
    35
    Rep Power
    0

    Default Re: Getting substring ???

    Does Strignbuffer will help me?

  6. #6
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: Getting substring ???

    It might.

  7. #7
    hacikho is offline Member
    Join Date
    Sep 2009
    Posts
    35
    Rep Power
    0

    Default Re: Getting substring ???

    Okay I kinda found below solution but actually it is not,
    Java Code:
    public static void main(String[] args) 
      {
          StringBuilder P = new StringBuilder("ABCED");
          StringBuilder str= new StringBuilder();
          for(int i=0; i<P.length(); i++)
          {
              str = P.deleteCharAt(i);
              System.out.println(str);
          }
      }
    this does not gives me what I want, it gives below result, so deletion seems not helpful. Do you have and idea?
    BCED
    BED
    BE

  8. #8
    vineetsahu87 is offline Member
    Join Date
    Nov 2011
    Posts
    1
    Rep Power
    0

    Cool Re: Getting substring ???

    You can use the StringBuffer to append the characters you want. Loop through the string and and getting the required substring and appending them.
    Last edited by vineetsahu87; 11-29-2011 at 04:34 AM.

  9. #9
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,762
    Rep Power
    7

    Default Re: Getting substring ???

    Please remove your code. Spoonfeeding fully coded solutions does not help people learn. It only helps them cheat.

  10. #10
    hacikho is offline Member
    Join Date
    Sep 2009
    Posts
    35
    Rep Power
    0

    Default Re: Getting substring ???

    How can I remove my previous reply (or edit it, to remove my code), I checked forum and could not find a solution, if anybody knows how to edit previouse reply please help me.

Similar Threads

  1. I don't know what I'm doing wrong in my substring.
    By Calaminh in forum New To Java
    Replies: 5
    Last Post: 11-08-2011, 06:03 AM
  2. substring Q
    By arsenal4ever_11 in forum NetBeans
    Replies: 1
    Last Post: 06-01-2010, 03:27 PM
  3. Help with substring
    By hiklior in forum New To Java
    Replies: 12
    Last Post: 06-28-2008, 06:48 AM
  4. How can i get substring
    By 82rathi.angara in forum New To Java
    Replies: 14
    Last Post: 06-27-2008, 04:35 AM
  5. substring
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-11-2007, 08:15 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
  •