title: Subtract two strings in javascript
body: <p>kwd variable holds this value:  <strong>news path:".aspx"</strong>
  It is basically the query string of an url.</p>
  
  <pre><code>  var path= "path:\".aspx\""; 
  </code></pre>
  
  <p>so kwd=  whatever user types passed to the url like this+path:</p>
  
  <pre><code>kwd=news path:".aspx";
  </code></pre>
  
  <p>I need to subtract kwd-path so i get only "news"
  How do i do that in java-script or jquery?</p>
  
  <p>I know i can either use trim or substring or substr..
  But I couldn't get to work .
  I am basically using this logic:</p>
  
  <pre><code>if (b.startsWith(a)) {
          return b.subString(a.length());
      }
  
      if (b.endsWith(a)) {
          return b.subString(0, b.length() - a.length());
      }
  </code></pre>
  
  <p>But this is not working..</p>
  
  <pre><code> var persistvalue= kwd.subString(0, kwd.length() - path.length());
  </code></pre>