title: How to erase certain characters in a string using a for loop?
body: <p>I'm trying to write a function that takes a <code>String</code> parameter str. It returns a new version where all the "x" characters have been removed. Except an "x" at the very start or end of str should not be removed. I can only use loops for this problem, not <code>StringBuilder</code> or <code>.replace()</code> method. </p>
  
  <p>I'm not sure how to erase a character at a certain string position. So far this is the code I have, any input would be greatly appreciated. </p>
  
  <pre><code>public String stringX(String str)
  {
      String result = str;
      int len = str.length() - 1;
  
  
      for (int i = 0; i &lt;= len; i++)
      {
          char letter = str.charAt(i);
          if (letter == 'x' &amp;&amp; ((i != 0) &amp;&amp; (i != len)))
          {
  
          } 
      }
  
      return result; 
  }
  </code></pre>