我有一張包含d??fi(défi) 或?–sterreich(?stereeich)文本的表格。
我可以通過這個腳本解碼第一個,另一方面我不能做第二個(我的意思是代碼需要 3 個位元組)
謝謝你的幫助!
function decode(txt){
var texte = []
for (i=0;i<txt.length;i ){
var n = txt.substring(i,i 1).charCodeAt()
if (n>127){
if ((n & 32) > 0){
//texte.push(decode_utf8(txt.substring(i,i 3))) ??
i =2
}
else{
texte.push(decode_utf8(txt.substring(i,i 2)))
i
}
}
else{
texte.push(txt.substring(i,i 1))
}
}
return (texte.join(''))
}
function decode_utf8(s) {
return decodeURIComponent(escape(s));
}
uj5u.com熱心網友回復:
這是一個解決方案......基于github
function utf8decode(utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length ) {
c = utftext.charCodeAt(i);
if (c < 128) {
string = String.fromCharCode(c);
i ;
}
else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i 1);
string = String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i = 2;
}
else {
c2 = utftext.charCodeAt(i 1);
c3 = utftext.charCodeAt(i 2);
string = String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i = 3;
}
}
return string;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/379790.html
標籤:javascript 谷歌应用程序脚本 谷歌表格 utf-8
上一篇:將Google表格獲取到可更新的JSON腳本以只需要標題行
下一篇:簡化保護腳本
