我如何 "decode" C# 中的 `ç` 值
How can I "decode" the `ç` value in C#
我有一个带有变音符号的字符串。该字符串在后面的代码中被编码为 ç
,然后在网页上显示为 ç
。我需要呈现字符串,但我不清楚如何在后端使用 C# 来呈现。
我试了.ToString()
和HttpUtility.HtmlDecode
,但是网页还是显示ç
,而不是ç,就是这样应该显示。
如何 "decode" C# 中的 ç
值?
代码如下。该字段是 CountryName
.
var countryList = (from x in listDataRow
join y in genericNameValueMetadataItemList on x.Field<string>("CountryISO") equals y.Value.Text into countryGroup
from item in countryGroup.DefaultIfEmpty(defaultGenericNameValueMetadataItem)
select new Country
{
CountryISO = x.Field<string>("CountryISO"),
CountryName = (!item.Title.Text.IsNullOrEmpty()) ? item.Title.Text : HttpUtility.HtmlDecode(x.Field<string>("CountryName"))
}).OrderBy(x => x.CountryName).ToList();
以下代码在我的控制台应用程序中运行良好。问题可能是因为 LINQ 语法吗?
Console.WriteLine(System.Web.HttpUtility.HtmlDecode("Curaçao"));
Console.WriteLine(System.Net.WebUtility.HtmlDecode("Curaçao"));
更新:
问题是我需要用 HtmlDecode 函数包装 item.Title.Text
代码以及 x.Field<string>("CountryName"))
代码。
问题是我需要用 HtmlDecode 函数包装 item.Title.Text
代码以及 x.Field<string>("CountryName"))
代码。
我有一个带有变音符号的字符串。该字符串在后面的代码中被编码为 ç
,然后在网页上显示为 ç
。我需要呈现字符串,但我不清楚如何在后端使用 C# 来呈现。
我试了.ToString()
和HttpUtility.HtmlDecode
,但是网页还是显示ç
,而不是ç,就是这样应该显示。
如何 "decode" C# 中的 ç
值?
代码如下。该字段是 CountryName
.
var countryList = (from x in listDataRow
join y in genericNameValueMetadataItemList on x.Field<string>("CountryISO") equals y.Value.Text into countryGroup
from item in countryGroup.DefaultIfEmpty(defaultGenericNameValueMetadataItem)
select new Country
{
CountryISO = x.Field<string>("CountryISO"),
CountryName = (!item.Title.Text.IsNullOrEmpty()) ? item.Title.Text : HttpUtility.HtmlDecode(x.Field<string>("CountryName"))
}).OrderBy(x => x.CountryName).ToList();
以下代码在我的控制台应用程序中运行良好。问题可能是因为 LINQ 语法吗?
Console.WriteLine(System.Web.HttpUtility.HtmlDecode("Curaçao"));
Console.WriteLine(System.Net.WebUtility.HtmlDecode("Curaçao"));
更新:
问题是我需要用 HtmlDecode 函数包装 item.Title.Text
代码以及 x.Field<string>("CountryName"))
代码。
问题是我需要用 HtmlDecode 函数包装 item.Title.Text
代码以及 x.Field<string>("CountryName"))
代码。