[英]How to convert string with wrong Turkish characters to show the correct characters?
[英]How to fix special Turkish characters in a string?
我有一個從 url 中提取的字符串作為包含特殊土耳其字符 (çğıİöüş) 的文件名,它們似乎是錯誤的。 我該如何解決?
public static string getFileName(HttpWebResponse response, string url)
{
var cd = response.Headers["content-disposition"];
var loc = response.Headers["location"];
if (!string.IsNullOrEmpty(cd))
{
var disp = ContentDispositionHeaderValue.Parse(cd);
return Uri.UnescapeDataString(disp.FileName);
}
else if (!string.IsNullOrEmpty(loc))
return Path.GetFileName(loc);
else
return Path.GetFileName(url);
}
原始字符串:
y2mate.com - Cengiz Özkan - Suzan Suzi (Kırklar Dağının Düzü)_VaW6Mhde9Ko.mp3
正確的字符串:
y2mate.com - Cengiz Özkan - Suzan Suzi (Kırklar Dağının Düzü)_VaW6Mhde9Ko.mp3
您似乎混合了Win-1254和Utf-8編碼:
string original =
@"y2mate.com - Cengiz Özkan - Suzan Suzi (Kırklar Dağının Düzü)_VaW6Mhde9Ko.mp3";
string correct = Encoding.UTF8.GetString(Encoding.GetEncoding(1254).GetBytes(original));
// Let's have a look
Console.Write(correct);
結果:
y2mate.com - Cengiz Özkan - Suzan Suzi (Kırklar Dağının Düzü)_VaW6Mhde9Ko.mp3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.