Replacing characters using javascript replace and substring
<p>I have a string in js like this:</p>

<pre><code>var frmSearch ="LoginID=:PersonName=:CallIDNumber=:NumberCalledTo=%2B92+3344038368:NumberCalledFrom=%2B92+3344038368:Notes="
</code></pre>

<p>I want to remove space (%2B) and replace + with ~ from NumberCalledTo and NumberCalledFrom. numbers can be of different length and LoginID, Call ID number can have value or be empty. Notes can be empty or have value.</p>

<p>I tried this but it is not working:</p>

<pre><code> frmSearch = frmSearch.substr(0, frmSearch.length - s.length);
        var NumberCalledTo = frmSearch.substr(frmSearch.indexOf(":NumberCalledTo"), frmSearch.indexOf(":NumberCalledFrom"));
        NumberCalledTo = NumberCalledTo.replace('+', '').replace('%2B', '~');
        var NumberCalledFrom = frmSearch.substr(frmSearch.indexOf(":NumberCalledFrom"), frmSearch.indexOf(":Notes"));
        NumberCalledFrom = NumberCalledFrom.replace('+', '').replace('%2B', '~');
</code></pre>

<p>Please suggest how to do it ?</p>
