我有一个名为联系人弗雷德里克
。
当我寻找它的联系人列表中的名称得到这样FRA©达©RIC
,因为它会搜索该名称( FRA©达©RIC )的数据库是我在它的名字弗雷德里克
。
When I search it in contacts list in the site the name gets changed like this "Frédéric"
, Since it searches this name(Frédéric
) in the database were I have the name Frédéric
in it.
所以不会有这样的数据库的名称,它说没有发现任何联系。
So there will not be a name like that in database it says no contacts found.
我如何获得真名不是这个名称等 FRA©达©RIC
?
How do I get the real name other than this name Frédéric
.?
我去code方法
public static string Decode(string text)
{
if (text == null)
{
return "";
}
string result = "";
string[] values = text.Split('@');
bool escaped = false;
try
{
for (int i = 0; i < values.Length; i++)
{
if (!escaped)
{
result += values[i].Replace("_"," ");
}
else
{
//result += System.Text.ASCIIEncoding.ASCII.GetChars(new byte[] { byte.Parse(values[i]) })[0];
}
escaped = !escaped;
}
}
catch { }
return result;
}
下面的方法的参数是FRA©达©RIC但它实际上已经成为弗雷德里克。
here the argument of the method is Frédéric but it actually has to be Frédéric.
您有一个错误的地方在你的系统中使用UTF-8 EN codeD字符串是使用所谓的ANSI $ C德codeD $ C页面。这code演示该bug:
You have a bug somewhere in your system where a UTF-8 encoded string is decoded using what is called the ANSI code page. This code demonstrates the bug:
var name = "Frédéric";
var bytes = Encoding.UTF8.GetBytes(name);
var wrongName = Encoding.Default.GetString(bytes);
现在 wrongName
是 FRA©达©RIC
。
您需要做的是这样的:
var name = "Frédéric";
var bytes = Encoding.UTF8.GetBytes(name);
var correctName = Encoding.UTF8.GetString(bytes);
在 Encoding.Default
的变化取决于您的Windows区域设置。在我的电脑在code页面的Windows 1252也被称为ISO 8859:1,但在世界其他地区也可以是另一个code页面。我认为,日本ANSI code页面932在这种情况下,错误的名称会出来为神父テゥÐテゥRIC
。
The Encoding.Default
varies depending on your Windows regional settings. On my computer the code page is Windows 1252 also known as ISO 8859:1 but in other parts of the world it may be another code page. I believe that the Japanese ANSI code page is 932 and in that case the wrong name will come out as Frテゥdテゥric
.
总之,正确的编码使用的是UTF-8,因为你的字符串连接使用该编码codeD。试图修补的错位字符串不是卓有成效的路径,因为它依赖于code执行对系统的ANSI code页面上。
Anyway, the correct encoding to use is UTF-8 because your string is encoded using that encoding. Trying to "repair" the mangled string is not a fruitful path because it depends on the ANSI code page of the system the code executes on.