C#解析带有'+'字符的问题

时间:2018-06-20 16:08:20

标签: c# string parsing encoding iso-8859-1

在此问题上,我需要您的帮助: 我的同事制作了一个程序(asp.net),该程序使您可以在文本框中写一个句子,然后将其放入Word文档中。 此代码运行特定的指令:

string item = "";
item = HttpUtility.UrlDecode(item, Encoding.GetEncoding("ISO-8859-1"));

在此“ ITEM”中,您可以编写任何内容;但是,如果您放置“ +”系列,则只会显示第一个。

"+ hello world +€"  -->  "+ hello world €".

有人可以告诉我为什么我写这么多'+'字符时,只显示第一个吗?

谢谢

1 个答案:

答案 0 :(得分:1)

问题在于UrlDecode方法将+解释为空格。尝试改用HttpUtility.HtmlDecode。 https://msdn.microsoft.com/en-us/library/7c5fyk1k(v=vs.110).aspx

string item = "+ hello world +€";
item = HttpUtility.HtmlDecode(item);