2010-07-12 81 views
5

我已经从服务器接收到的URL编码字符串,如HTTP%3A%2F%2fstatic.csbew.com%2F%2fcreative%2fpd_test_pptv%2f320x60.png如何解码Windows Mobile上的URL编码字符串?

我想将它解码成正常的URL字符串。我找到了这个方法,但是这不适用于紧凑的框架。

string url = System.Web.HttpUtility.UrlDecode(strURL, Encoding.GetEncoding("GB2312")); 

有关如何解码字符串的任何想法?

回答

10

也许这将帮助你:

/// <summary> 
    /// UrlDecodes a string without requiring System.Web 
    /// </summary> 
    /// <param name="text">String to decode.</param> 
    /// <returns>decoded string</returns> 
    public static string UrlDecode(string text) 
    { 
     // pre-process for + sign space formatting since System.Uri doesn't handle it 
     // plus literals are encoded as %2b normally so this should be safe 
     text = text.Replace("+", " "); 
     return System.Uri.UnescapeDataString(text); 
    } 

    /// <summary> 
    /// UrlEncodes a string without the requirement for System.Web 
    /// </summary> 
    /// <param name="String"></param> 
    /// <returns></returns> 
    public static string UrlEncode(string text) 
    { 
     // Sytem.Uri provides reliable parsing 
     return System.Uri.EscapeDataString(text); 
    } 

这里最初发现:geekstoolbox