Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert binary MS Office) data to string

Status
Not open for further replies.

sigrney2

Programmer
May 7, 2008
1
US
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. !!
 
Take a look at the code (and demo) here. It works on encoding and decoding UTF-8 data using javascript, and may be of help.

Cheers,
Jeff

[tt]Jeff's Blog [!]@[/!] CodeRambler
[/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top