2

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

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;
}

谢谢

4

2 回答 2

0

小提琴

看看这个..

   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("ı Å? ö"))
​
于 2012-08-22T21:10:18.683 回答
0

你可以使用这个扩展

public static string ReplaceToTurkishChar(this string input)
{
        if (string.IsNullOrEmpty(input))
            return input;

        input = input
            //.Replace("&#305;", "ı").Replace("&#304;", "İ")
            .Replace("&Uuml;", "Ü").Replace("&uuml;", "ü")
            .Replace("&Ouml;", "Ö").Replace("&ouml;", "ö")
            //.Replace("&#286;", "Ğ").Replace("&#287;", "ğ")
            //.Replace("&#350;", "Ş").Replace("&#351;", "ş")
            .Replace("&Ccedil;", "Ç").Replace("&ccedil;", "ç");


        input = input
            .Replace("&#305;", "ı").Replace("&#304;", "İ")
            .Replace("&#220;", "Ü").Replace("&#252;", "ü")
            .Replace("&#214;", "Ö").Replace("&#246;", "ö")
            .Replace("&#286;", "Ğ").Replace("&#287;", "ğ")
            .Replace("&#350;", "Ş").Replace("&#351;", "ş")
            .Replace("&#199;", "Ç").Replace("&#231;", "ç");


        input = input
            .Replace("ı", "ı").Replace("Ä°", "İ")
            .Replace("ü", "ü").Replace("Ãœ", "Ü")
            .Replace("Ö", "Ö").Replace("ö", "ö")
            .Replace("ÄŸ", "ğ").Replace("Ä?", "Ğ")
            .Replace("ÅŸ", "ş").Replace("Åž", "Ş")
            .Replace("Ç", "Ç").Replace("ç", "ç");



        input = input
            .Replace("\u0131", "ı").Replace("\u0130", "İ")
            .Replace("\u00FC", "ü").Replace("\u00DC", "Ü")
            .Replace("\u00F6", "ö").Replace("\u00D6", "Ö")
            .Replace("\u011F", "ğ").Replace("\u011E", "Ğ")
            .Replace("\u015F", "ş").Replace("\u015E", "Ş")
            .Replace("\u00E7", "ç").Replace("\u00C7", "Ç");

        return input;
}
于 2016-03-10T08:48:15.317 回答