I have an app where users often copy text from a Word document which is stored in a database. I need to convert the binary to simple ascii for later use. The following function seems to work with most characters, it gets the charCodeAt, replaces control characters with a space and then tries to replace special chars over unicode 126 with the string version. It doesn't work with the (-) in Word, which it turns out translates to char code 8211. Instead of a "-" I get a "?" saved to the database.
function cleanValues(s) {
var newstr = "";
var temp = "";
for(var i = 0; i < s.length; i++) {
temp = s.charCodeAt(i);
if(temp > 31 && temp < 127) newstr += s.charAt(i);
if(temp < 32) newstr += " ";
if(temp > 126)newstr += String.fromCharCode(temp);
}
return newstr;
}
T.I.A. !!
function cleanValues(s) {
var newstr = "";
var temp = "";
for(var i = 0; i < s.length; i++) {
temp = s.charCodeAt(i);
if(temp > 31 && temp < 127) newstr += s.charAt(i);
if(temp < 32) newstr += " ";
if(temp > 126)newstr += String.fromCharCode(temp);
}
return newstr;
}
T.I.A. !!