How can I decode HTML characters in C#?

前端 未结 10 2150
夕颜
夕颜 2020-11-22 03:38

I have email addresses encoded with HTML character entities. Is there anything in .NET that can convert them to plain strings?

10条回答
  •  迷失自我
    2020-11-22 03:47

    Write static a method into some utility class, which accept string as parameter and return the decoded html string.

    Include the using System.Web.HttpUtility into your class

    public static string HtmlEncode(string text)
        {
            if(text.length > 0){
    
               return HttpUtility.HtmlDecode(text);
            }else{
    
             return text;
            }
    
        }
    

提交回复
热议问题