2017-05-26 190 views
0

我正在嘗試使腳本將文本變成這些很酷的外觀字母,它看起來像一切都應該工作,但是當我嘗試發送替換的消息時,它會給我像黑色背景上的白色問號的字符。這:用數組中的字符替換字符串中的字符

下面的代碼:

var mm = "test"; 
    var alphabet = ""; 
    var nalphabet = "abcdefghijklmnopqrstuvwxyz";  
    for(var z in mm){ 
    var x = nalphabet.indexOf(mm[z].toLowerCase()); 
    var ool = alphabet[x]; 
    msg.channel.sendMessage(ool); 
    } 
+0

那些帶有問號的小調字符是錯誤編碼的標誌。這意味着至少有兩種類型的編碼,通常是ASCII和UTF8。檢查您的數據庫,文件和HTTP標頭編碼。 – Booster2ooo

+0

如果我理解正確,你想把一個像''test''這樣的字符串改成''「',那是正確的嗎? –

回答

0

這是所有關於字符的編碼。每個看起來很酷的字母都有長度爲2.所以當你試圖通過索引直接得到這樣的字符時,你會收到它的一半。作爲一種解決方案,您可以嘗試加入兩個兄弟角色。這樣

var mm = "test"; 
    var alphabet = ""; 
    var nalphabet = "abcdefghijklmnopqrstuvwxyz";  
    for(var z in mm){ 
    var x = nalphabet.indexOf(mm[z].toLowerCase()); 
    var ool = alphabet[x * 2] + alphabet[x * 2 + 1]; 
    msg.channel.sendMessage(ool); 
    } 
+0

它的工作!謝謝 – Inferno

0

東西試試這個:

var message = "test"; 
var alphabet = ["","","","","", 
       "","","","","", 
       "","","","","", 
       "","","","","", 
       "","","","","",""]; 
var nalphabet = "abcdefghijklmnopqrstuvwxyz";  
for(var letter in message) { 
    var x = nalphabet.indexOf(message[letter].toLowerCase()); 
    var ool = alphabet[x]; 
    document.write(ool); 
} 

這裏是一個Fiddle