c#实现Javascript的encodeURIComponent()函数

国内外各搜索引擎,均用JavaScript的encodeURIComponent()函数对搜索关键字进行编码,终于找到了.net下的实现方法。

.net采用

System.Text;

UrlDecode(String, Encoding)
使用指定的编码对象将 URL 编码的字符串转换为已解码的字符串。

Encoding 能过查看 http://msdn.microsoft.com/zh-cn/library/system.text.encoding.aspx

代码页

Name
显示名称

936

gb2312
简体中文 (GB2312)

65001

utf-8
Unicode (UTF-8)

国内各搜索引擎均采用GB2312,使用此类搜索引擎时,编码为:

HttpUtility.UrlEncode(String, System.Text.Encoding.GetEncoding(936))

现在这问题解决了,可以不再只限于采用UTF-8编码的Google做搜索工具

原文地址:https://www.cnblogs.com/suizhikuo/p/2958362.html