gpt4 book ai didi

javascript - 将字符串中的字符替换为土耳其语配置

转载 作者:行者123 更新时间:2023-11-30 06:40:02 25 4
gpt4 key购买 nike

我的站点有聊天功能,但该功能无法正确显示土耳其语字符。所以,我在下面写了这个函数,但它什么也没返回。哪里出错了?文本以字符串形式获取注释。

function FindAndReplaceAll(text) 
{
var normal = new Array("ı","Å?","ü","ç","ö","Ä?","ÅŸ","Ç","Ä°","ÄŸ","Åž","Ö","Ãœ","ı","Å?","ç","ö","Ä?","ÅŸ","Ç","Ä°","ÄŸ","Åž","Ö","Ãœ","ü","ÄŸ");
var turkish = new Array("ı","ş","ü","ç","ö","ğ","ş","Ç","i","ğ","Ş","Ö","Ü","ı", "ş", "ç", "ö", "ğ", "ş", "Ç", "i", "ğ", "Ş", "Ö", "Ü", "ü", "ğ");

for (var i = 0; i < text.length; i++)
{
for(var j = 0; j < 27;j++)
{
if(text.charAt(i) == normal[j])
{
text.charAt(i) = turkish[j];
}

}
}


return text;
}

谢谢

最佳答案

FIDDLE

检查一下..

   function FindAndReplaceAll(text) 
{
var normal = new Array("ı","Å?","ü","ç","ö","Ä?","ÅŸ","Ç","Ä°","ÄŸ","Åž","Ö","Ãœ","ı","Å?","ç","ö","Ä?","ÅŸ","Ç","Ä°","ÄŸ","Åž","Ö","Ãœ","ü","ÄŸ");
var turkish = new Array("ı","ş","ü","ç","ö","ğ","ş","Ç","i","ğ","Ş","Ö","Ü","ı", "ş", "ç", "ö", "ğ", "ş", "Ç", "i", "ğ", "Ş", "Ö", "Ü", "ü", "ğ");

for (var i = 0; i < text.length; i+=2)
{
for(var j = 0; j < 27;j++)
{
if((text.charAt(i)+text.charAt(i+1)) == normal[j])
{

text= text.replace((text.charAt(i)+text.charAt(i+1)), turkish[j]);
}

}
}


return text;
}
document.write(FindAndReplaceAll("ı Å? ö"))

关于javascript - 将字符串中的字符替换为土耳其语配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12081232/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com