url转义。绝对正确的url转义的东西

在阿里上班积累的字符串转义 JS的写法
encodeURIComponent(window.location.href);
decodeURIComponent(window.location.href);
 
如果是C#的写法呢 

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做搜索工具

 
 

posted on 2021-08-14 18:13  漫思  阅读(147)  评论(0编辑  收藏  举报

导航