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

Thread: how to delete first letter of string

  1. #1
    Member
    Join Date
    Aug 2013
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how to delete first letter of string

    Here is my code:

     public static String[] guillotine( String[] inArray ) 
     
    {
     for (int i = 0; i < a.length - 1; i++){
             System.out.print(a[i].substring(1)); 
     }
    }
      String[] a = {   }; 
      String[] b = guillotine( a ); 
     
      System.out.println( b[  ] );

    Thanks.


  2. #2
    Member
    Join Date
    Apr 2012
    Posts
    160
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: how to delete first letter of string

    Firstly, these forums are not meant for us to plainly write out solutions for you, they are here to guide you.

    Second, you are using an array of Strings, which I don't think is the data type you are looking for since this would contain multiple strings, not characters. Without more information it's hard to know.

    Thirdly, your code won't compile which suggests you might be missing some basic fundamental parts of the Java language.

    If you have questions, go ahead and ask, but again we are not here to just give you a solution.

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: how to delete first letter of string

    Quote Originally Posted by Parranoia View Post
    Second, you are using an array of Strings, which I don't think is the data type you are looking for since this would contain multiple strings, not characters.
    Unless they plan on the array containing one character long Strings.
    String[] word = {"h", "e", "l", "l", "o"};
    But it would be nice if OP provided better/more information. It can be achieved with a single call to substring but it seems there is a recursion requirement to the assignment.
    Improving the world one idiot at a time!

  4. #4
    Member
    Join Date
    Aug 2013
    Posts
    101
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how to delete first letter of string

    Originally, I didn't have anything within the brackets. I'm supposed to put something in there. I think though, that since I'm filling in the blank, do I have to put in another "public static?" I mean, what sort of thing do I put in the brackets exactly? Is it a for-loop, if-statement, array...? I think the whole thing involves an array. Basially, if a = {"meat", "flat", "flukes"}, then it should be a = {"eat", "lat", "lukes"}.

    So yes, I'm using strings. I tried "substring()" but I couldn't get to the bottom of how to use it. Do I need to use "substring()" here? That's the conclusion I come to, but I don't think I'm doing it right.

    My idea (which I don't know how to implement) is, for each string in the array, to find the first letter of each string imputed and delete it automatically. Then it would print it.

    Which fundamentals am I missing?



    Hope that helps.

    Thanks, ghostheadx


  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: how to delete first letter of string

    "substring()" but I couldn't get to the bottom of how to use it.
    Take a look at the API doc for the String class. Remember that Strings can't be changed. methods that operate on the contents return a new String with the changes
    Then write a short simple program that uses it.
    Print out the results.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to capitalize a letter in String?
    By garbage in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 12th, 2013, 09:03 AM
  2. [SOLVED] Hangman Program Java: Comparing the User's Guess with Another String Letter by Letter
    By theonlydvr in forum What's Wrong With My Code?
    Replies: 4
    Last Post: June 29th, 2013, 05:35 PM
  3. Finding the count of a letter in a String?
    By vlkn448 in forum Algorithms & Recursion
    Replies: 7
    Last Post: July 15th, 2012, 11:55 AM
  4. letter pattern
    By severus1 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 4th, 2011, 01:24 PM
  5. Incrementing every letter in a string that occupies an odd position.
    By haktheplanet in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 22nd, 2010, 04:45 AM

Tags for this Thread