代码之家  ›  专栏  ›  技术社区  ›  Chilly Zhong

如何在Windows Mobile上解码URL编码字符串?

  •  5
  • Chilly Zhong  · 技术社区  · 16 年前

    我从服务器收到了一个URL编码字符串,例如 http%3a%2f%2fstatic.csbew.com%2f%2fcreative%2fpd_test_pptv%2f320x60.png

    我想将其解码为普通的URL字符串。我找到了这个方法,但它不适用于紧凑的框架。

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

    知道如何解码字符串吗?

    1 回复  |  直到 16 年前
        1
  •  10
  •   Aykut Çevik    16 年前

    也许这能帮助你:

     /// <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

    推荐文章