zoukankan      html  css  js  c++  java
  • 将字符串URL编码

     1 int URLEncode( const CString& rawStr,CString& encodeStr )
     2 {
     3 #ifdef _UNICODE
     4     std::string strPre = wstring2string((LPCTSTR)rawStr).c_str();
     5     std::string strEncoded;
     6     char*   szHexTable = "0123456789ABCDEF",
     7         *    szUnsafeTable = ""<>%\^[]`+$,@:;/!#?=&" ;
     8     for (int i=0 ; i < strPre.size(); i++){
     9         if (((unsigned char)strPre[i] > 32) && ((unsigned char)strPre[i] < 123) && ( strchr(szUnsafeTable,(unsigned char)strPre[i])== NULL )){
    10             strEncoded += (unsigned char)strPre[i] ;
    11         }
    12         else{
    13             strEncoded += "%" ;
    14             strEncoded += szHexTable[(unsigned char)strPre[i] / 16] ;
    15             strEncoded += szHexTable[(unsigned char)strPre[i] % 16] ;
    16         }
    17     }
    18 
    19     encodeStr = string2wstring(strEncoded).c_str();
    20     return encodeStr.GetLength() ;
    21 #else
    22     ASSERT(FALSE);
    23 #endif
    24 
    25 }

    只是简略实现,不确定@等符号是否需要转码。

  • 相关阅读:
    https://github.com/cykl/infoqscraper/
    C# 笔记
    json.org
    python html parse
    doxygen
    review board
    ruunlevel debian
    连接REDIS
    composer
    php需要注意的地方
  • 原文地址:https://www.cnblogs.com/aishangxue/p/3384900.html
Copyright © 2011-2022 走看看