title: How to shorten a string by replacing some characters with an ellipsis
body: <p>I am using an <code>&lt;input type=&quot;file&quot;&gt;</code> element for file upload, and getting the filename. I am now trying to display the file name, but reduce the total string length. To achieve that, I wanted to add an ellipsis at a specific index and display the rest of the characters.</p>
  <p>Like for example: if the filename is <strong>abcxyz.exe</strong>, I want the filename to look like <strong>abc..z.exe</strong>.</p>
  <p>Is there any way to display it in this way ?</p>
  <p>I am using this method, but it adds an ellipsis to replace all characters from the position given as a parameter.</p>
  <pre><code>function truncate(str, n){
      return (str.length &gt; n) ? str.substr(0, n-5) + '&amp;hellip;' + str.substring(str.indexOf(&quot;.&quot;) + 1) : str;
  };
  </code></pre>