JavaScript hexadecimal to ascii character replace by regex

时间:2016-02-12 20:12:41

标签: javascript

I want to translate hexadecimal results into ASCII character

I try this but I can't do it:

output.content = decodeResults[0].content.replace("%3C0xc5%3E%3C0x9f%3C%3E", "asd");

My char hex code is <0xc5><0x9f>

default code

    // Default script for data formatting
function onResult (decodeResults, readerProperties, output)
{
    if (decodeResults[0].decoded)
    {
        output.content = decodeResults[0].content;
    }
}

2 个答案:

答案 0 :(得分:0)

I found it

skip_first

But i can't find a solution for show it as "ş" character.

答案 1 :(得分:-1)

Do you know the format of your decodeResults[0].content ? Your replace statement suggests a URL-encoded string. JavaScript replace is not specifically concerned with this type of encoding, it handles input as just a series of characters.

For this input: '<0xc5><0x9f>' I'd suggest escaping the < and > characters:

"(?m).*\\S.*$"

Check it out at the JSFiddle I created: JSFiddle for replace