I have the following code and would like to do a global replace of chars in a string but it only replaces the first occurrence. How do I get it to replace all occurrences?
sBadChars[0] = "+";
sBadChars[1] = "%2B";
sBadChars[2] = "%20";
sBadChars[3] = "%2520";
sBadChars[4] = "%22";
for (iCount = 0; iCount < sBadChars.length; iCount++)
{
iFound = sTemp.indexOf(sBadChars[iCount])
if (iFound > -1)
{
sFinal = sTemp.replace(sBadChars[iCount], " ");
}
}
return sFinal;
sBadChars[0] = "+";
sBadChars[1] = "%2B";
sBadChars[2] = "%20";
sBadChars[3] = "%2520";
sBadChars[4] = "%22";
for (iCount = 0; iCount < sBadChars.length; iCount++)
{
iFound = sTemp.indexOf(sBadChars[iCount])
if (iFound > -1)
{
sFinal = sTemp.replace(sBadChars[iCount], " ");
}
}
return sFinal;