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: Separating Strings

  1. #1
    Member Scorks's Avatar
    Join Date
    Jan 2013
    Posts
    56
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Separating Strings

    Hello there!

    I'm working on a program that will take an input (i.e: "This is a test"), and outputs it scrambled, but having the first and last letter of each word in the same place (i.e: "Tihs is a tset"). I know that I should first separate the input string into their own string values. I'm aware of using input.split(), but I'm not sure how to assign each word to it's own name (i.e: word1, word2, word3 etc...)

    Any help would be appreciated!

    Thank you,
    Scorks


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default Re: Separating Strings

    Strings can be concatenated. In other words you can add Strings with a + sign. e.g., String foo = "foo" + "bar" will result in "foobar". With this knowledge and a for loop, I'll bet you can figure this out.

    Note, in the future there will be times when you'll want to use a StringBuilder to do this sort of concatenation, since it is more efficient at it, but for your simple needs, the benefit is less than minimal and so I suggest you keep things as simple as possible and just use plain String concatenation.

Similar Threads

  1. Literally, what's wrong with my code? Separating X and Y coordinates.
    By liamb109 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: October 9th, 2012, 07:53 AM
  2. Separating Digits in a String
    By Staticity in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 3rd, 2011, 06:39 AM
  3. Strings
    By Leeds_Champion in forum Algorithms & Recursion
    Replies: 3
    Last Post: November 3rd, 2009, 10:09 PM
  4. Strings
    By BeSwift21 in forum Java Theory & Questions
    Replies: 1
    Last Post: October 13th, 2009, 07:02 PM
  5. Replies: 2
    Last Post: June 19th, 2008, 03:58 AM

Tags for this Thread