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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -