不同语系的转码、编码 --- HttpUtility.UrlEncode,Server.UrlEncode两者差异

不同语系的转码、编码 -- HttpUtility.UrlEncode,Server.UrlEncode两者差异

http://www.dotblogs.com.tw/mis2000lab/archive/2008/06/11/4268.aspx

 

 

 

 

多国语系的转码 / UrlEncode。各位可以参考一下微软的范例,

 

名称 

说明 

Encoding.Convert (Encoding_A, Encoding_B, Byte[])

将整个字节数组从一种编码方式(A)转换成另一种编码方式(B)。

受 .NET Compact Framework 支援。

  -------------------------------------------------------------------------------

 

 以下是微软的范例程序,很有用。(抄起来,就能用)

Imports System

Imports System.Text
Imports Microsoft.VisualBasic

Namespace Convert_Example
   Class MyConvertExampleClass
       Shared Sub Main()
           Dim unicodeString AsString = "This stringcontains the unicode character Pi(" & ChrW(&H03A0) & ")"

           ' Create two different encodings.  ASCII与 Unicode两者互转
           Dim ascii As Encoding= Encoding.ASCII
           Dim [unicode] AsEncoding = Encoding.Unicode

           ' Convert the string into a byte[].
           Dim unicodeBytes AsByte() = [unicode].GetBytes(unicodeString)

           ' Perform the conversion from one encoding to the other.这段程序很麻烦,一定要先用Byte型态之后,才能转码!
           Dim asciiBytes AsByte() = Encoding.Convert([unicode],ascii, unicodeBytes)


           ' Convert the new byte[] into a char[] and then intoa string.
           ' This is a slightly different approach to convertingto illustrate
           ' the use of GetCharCount/GetChars.
           Dim asciiChars(ascii.GetCharCount(asciiBytes, 0,asciiBytes.Length)) As Char
           ascii.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0)
           Dim asciiString AsNew String(asciiChars)

           ' Display the strings created before and after the conversion.
           Console.WriteLine("Original string: {0}",unicodeString)
           Console.WriteLine("Ascii converted string: {0}",asciiString)
       End Sub
   End Class
End Namespace

 

  -------------------------------------------------------------------------------

 

关于HttpUtility.UrlEncodeServer.UrlEncode两者的差异(本文为简体中文)

详见全文:http://bbs.wangqi.com/showtopic-7609.html


1. HttpUtility.UrlEncode 方法:
    对 URL 字符串进行编码,以便实现从 Web 服务器到客户端的可靠的 HTTP 传输。

2. Server是HttpServerUtility类的实例,是System.Web.UI.Page的属性。
HttpServerUtility.UrlEncode 方法:
    编码字符串,以便通过 URL 从 Web 服务器到客户端进行可靠的 HTTP 传输。

需要注意的几点(两者差异如下):
1、HttpUtility.UrlEncode,HttpUtility.UrlDecode是静态方法,而Server.UrlEncode,Server.UrlDecode是实例方法。
2、Server是HttpServerUtility类的实例,是System.Web.UI.Page的属性。
3、用HttpUtility.UrlEncode编码后的字符串和用Server.UrlEncode进行编码后的字符串对象不一样

  论:

 -------------------------------------------------------------------------------

 

另外有一篇好文章,是给VB.NET使用的 URLEncode。

标题「如何用 VB 或 VB.Net 来撰写 ASP 的 Server.URLencode 函数  (作者:强力榔头)」

 

另外一篇相关文章,是「黑暗执行绪」写的----【茶包射手专栏】QueryString的中文编码问题

网络上找到的相关文章,转贴_JavaScript的UrlEncode,UrlDecode

 -------------------------------------------------------------------------------

 

 

转载于:https://www.cnblogs.com/mis2000lab/archive/2010/10/18/2008_06_11_4268_UrlEncode.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值