2016-02-12 176 views
-2

你好,我想更換十六進制結果ASCII字符JavaScript的十六進制ASCII字符的正則表達式替換

我嘗試這一點,但icant做

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

我的字符的十六進制代碼是< 0xc5> < 0x9f>

默認代碼

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

如果你的意思是你想unescape,請嘗試'unescape','decodeURI'或'decodeURIComponent'。 – Oriol

+0

它來自條形碼閱讀器。我想寫一個腳本給條碼閱讀器。 –

回答

-1

你知道decodeResults [0] .content的格式嗎?您的替換語句建議使用URL編碼的字符串。 JavaScript替換並不特別關注這種類型的編碼,它將輸入作爲一系列字符來處理。

此輸入: '< 0xc5> < 0x9f>' 我建議逃脫<和>字符:

.replace('\<0xc5\>\<0x9f\>', 'asd') 

檢查它在我的jsfiddle創建:JSFiddle for replace

0

我發現它

function onResult (decodeResults, readerProperties, output) 
{ 
    if(decodeResults.toString) 
    { 
     var OkunanBarkod = decodeResults[0].content; 

      while(OkunanBarkod.match('\xc5') && OkunanBarkod.match('\x9f') && (OkunanBarkod.indexOf('\xc5') == (OkunanBarkod.indexOf('\x9f')-1))) 
      {  
       OkunanBarkod = OkunanBarkod.replace('\xc5', 's'); 

       OkunanBarkod = OkunanBarkod.replace('\x9f', '');    
      } 

      while(OkunanBarkod.match('\xc3') && OkunanBarkod.match('\xb6') && (OkunanBarkod.indexOf('\xc3') == (OkunanBarkod.indexOf('\xb6') - 1))) 
      {  
       OkunanBarkod = OkunanBarkod.replace('\xc3', 'o'); 

       OkunanBarkod = OkunanBarkod.replace('\xb6', '');    
      } 



      output.content = OkunanBarkod; 

    } 
    else{ 
     output.content = "no"; 
    } 

但我找不到解決方案顯示它爲「ş」字符。

相關問題