I'm trying to use the replace method to replace all instances of "a" and "b" characters within a string, but I'm running into a problem. I have accomplished this in my
VB version without a problem, but the JavaScript version is only replacing the first instance of the character in the string. I've included all of the referenced code below. If anyone could please let me know what I'm doing wrong, that would be great. Thanks for any and all help.
Problem:
JS version replaces only the first instance of a character, while the
VB version replaces all instances of characters.
Example value: bababa
VB version (works):
'Declare variables
Dim strA As String = "ZZ~"
Dim strB As String = "YY~"
Dim strValue_display As String = strValue_original
strValue_display = strValue_display.replace("a",strA)
Response.Write("strValue_display (a):" & strValue_display & "<br />")
strValue_display = strValue_display.replace("b",strB)
Response.Write("strValue_display (b):" & strValue_display & "<br />")
'Resulting value: YY~ZZ~YY~ZZ~YY~ZZ~
JScript version (doesn't work):
//Declare variables
var strA = "ZZ~";
var strB = "YY~";
var strValue_display = strValue_original;
strValue_display = strValue_display.replace("a",strA);
Response.Write("strValue_display (a):" + strValue_display + "<br />");
strValue_display = strValue_display.replace("b",strB);
Response.Write("strValue_display (b):" + strValue_display + "<br />");
//Resulting value: YY~ZZ~baba
KWilliams