title: Replace extension of a filename in swift
body: <p>Given an string with format <code>filename.fileextension</code> I want to replace the fileextension with <code>newextension</code>. How can I do it?</p>
  
  <p>In java it would be</p>
  
  <pre><code>foo.substring(0, foo.lastIndexOf(".")) + ".newextension"
  </code></pre>