title: How to 'subtract' one string from another?
body: <p>Suppose I have the following two strings:</p>
  
  <pre><code>var value = "1-000-111";
  var mask = " -   -";
  </code></pre>
  
  <p>I want to <em>subtract</em> the <code>mask</code> from the <code>value</code>. In other words I want something like this:</p>
  
  <pre><code>var output = subtract(value, mask);
  // output should be 1000111
  </code></pre>
  
  <p>What is the best way to implement <code>subtract()</code>? I have written this, but that doesn't seem elegant to me.</p>
  
  <pre><code>function subtract(value, mask) {
      while (mask.indexOf('-') &gt;= 0) {
          var idx = mask.indexOf('-');
          value = value.substr(0, idx) + value.substr(idx + 1);
          mask = mask.substr(0, idx) + mask.substr(idx + 1);
      }
      return value;
  }
  </code></pre>
  
  <p>Does JavaScript have something built-in to accomplish this? Note that, the masking characters are not limited to <code>-</code> (dash), but can be other characters as well, like <code>+</code>. But in a given case, the masking character can only be either <code>-</code> or <code>+</code>, which can therefore be sent to the <code>subtract()</code> function, which makes handling different masking character trivial. Also, the masking characters will be in arbitrary positions.</p>
  
  <p>Any language-agnostic answers are also welcome.</p>