Warm tip: This article is reproduced from stackoverflow.com, please click
c# encoding

How to convert string with wrong Turkish characters to show the correct characters?

发布于 2020-04-07 10:22:34

I have a string with ASCII characters like

"Tu%C4%9F%C3%A7e%20Kandemir%20-%20G%C3%BCl%C3%BC%20Soldurmam.mp3" 

The correct filename is

"Tuğçe Kandemir - Gülü Soldurmam" 

How can I convert it?

Questioner
Ali Tor
Viewed
171
haldo 2020-02-01 02:45

That string looks like its been encoded for a URL.

You can use UrlDecode from System.Web.HttpUtility:

var encoded = "Tu%C4%9F%C3%A7e%20Kandemir%20-%20G%C3%BCl%C3%BC%20Soldurmam.mp3";
var decoded = HttpUtility.UrlDecode(encoded);

Or if you're not using a web application, you can use System.Net.WebUtility.UrlDecode:

var decoded = WebUtility.UrlDecode(encoded);

Both of these output the following string:

"Tuğçe Kandemir - Gülü Soldurmam.mp3"