- 有時需要進行url編碼、解碼,比如從html中撈數據,有可能>、&等字符會被編碼成>等。
- WinForm中默認沒有引入System.Web,因此要現在項目中引入依賴
- System.Web.HttpUtility.HtmlEncode(str);
- System.Web.HttpUtility.HtmlDecode(str);
- System.Web.HttpUtility.UrlEncode(str);
- System.Web.HttpUtility.UrlDecode(str);
- 編碼、解碼時可以指定編碼,否則會看到亂碼,如:
- System.Web.HttpUtility.UrlEncode(str,System.Text.Encoding.Unicode);
- System.Web.HttpUtility.UrlEncode(str,System.Text.Encoding.UTF8);
- System.Web.HttpUtility.UrlEncode(str,System.Text.Encoding.GetEncoding( "GB2312 "));
- System.Web.HttpUtility.UrlDecode(str,System.Text.Encoding.Unicode);
- System.Web.HttpUtility.UrlDecode(str,System.Text.Encoding.UTF8);
- System.Web.HttpUtility.UrlDecode(str,System.Text.Encoding.GetEncoding( "GB2312 "));
- 等
