javascript - Using replace() on decoded URI hex codes with native division operator -
building calculator.
var process = "6÷6"; // need replace division sign 1 javascript can evaluate process = encodeuri(process); process.replace(/%c3%b7/gi,'/'); // replacement step doesn't work - %c3%b7 shows hex divison sign in chrome debugger, not sure why process = decodeuri(process); result = eval(process);
the third line of code wrong. have assign return value of replace function variable. easiest way assign itself:
process = process.replace(/%c3%b7/gi,'/');
so whole script code this:
var process = "6÷6"; // need replace division sign 1 javascript can evaluate process = encodeuri(process); process = process.replace(/%c3%b7/gi,'/'); // replacement step works process = decodeuri(process); result = eval(process);
Comments
Post a Comment