title: Replacing a particular word in a scanned in string and concatenating using substring() in Java
body: <p>I'm brand new to all of this so I am trying to write a simple bit of code that allows the user to type in text (saved as a string) and then have the code search for the position of a word, replace it and join the string back together. I.e.: </p>
  
  <p>'I like foo for lunch'</p>
  
  <p>foo is found at position 7</p>
  
  <p>The new input is: I like Foo for lunch</p>
  
  <p>Here is what I have thus far:</p>
  
  <pre><code>import java.util.Scanner;
  
  public class FooExample
  {
  
  public static void main(String[] args) 
      {
  
      /** Create a scanner to read the input from the keyboard */
  
      Scanner sc = new Scanner (System.in);
  
      System.out.println("Enter a line of text with foo: ");
      String input = sc.nextLine();
      System.out.println();
      System.out.println("The string read is: " + input);
  
  
      /** Use indexOf() to position of 'foo' */
  
      int position = input.indexOf("foo");
      System.out.println("Found \'foo\' at pos: " + position);
  
              /** Replace 'foo' with 'Foo' and print the string */
  
      input = input.substring(0, position) + "Foo";
      System.out.println("The new sentence is: " + input);
  </code></pre>
  
  <p>The problem is occurring at the end -- where I am stumped on how to tack the rest of the sentence on to the concatenation:</p>
  
  <pre><code>input = input.substring(0, position) + "Foo";
  </code></pre>
  
  <p>I can get the word to be replaced but I am scratching my head over how to get the rest of the string attached on.</p>