Use split("//s") on your String object to form an array of words from the input. Then, reassemble the string, using your replacement word for the first element of the returned array, and the rest of the words in order from the array.
A best practice is to use a StringBuffer to construct your new string using the append method for each word, and when constructed, use toString() to get the final string value, but this is not absolutely necessary.
dononelson
Junior Poster in Training
62 posts since Mar 2010
Reputation Points: 13
Solved Threads: 15
Skill Endorsements: 0
Well, I think you can first separate your input into paragraphs with split(""\\r?\\n") (I believe that's the right regex). A newline in the text would effectively mean it's a new paragraph, right? Each paragraph would go into its own ArrayList. You can keep those array lists in another array list so you don't have to worry about keeping track of individual array lists.
As far as the spaces go, just concatenate all the words with a space after each one, then use trim() to remove the final space. Or, use some logic to know that you don't add a space after the last word in the paragraph.
dononelson
Junior Poster in Training
62 posts since Mar 2010
Reputation Points: 13
Solved Threads: 15
Skill Endorsements: 0