Javascript Convert Unicode Embedded strings -
i'm getting passed string api method have no control on returns strings paths like: /toplevel/nextlevel/_x0034_33name/myoutput.log
it seems happens directory names start number. in case directory name should '433name'.
i'm guessing x0034 represents hex character '4', possibly in unicode.
the following javascript returns '4', correct:
string.fromcharcode(parseint("0034",16))   is there regex command or conversion utility in javascript readily available remove , replace these characters in string correct equivalents?
function unescapeapi(string) {     return string.replace(/_x([\da-f]{4})_/gi, function(match, p1) {         return string.fromcharcode(parseint(p1, 16));     }); }  # example, logs '/433name/myoutput.log' console.log(unescapeapi('/_x0034_33name/myoutput.log'));      
Comments
Post a Comment