2009-11-13 16 views
1

Je travaille dans MFC et obtenir le code suivant en html:Comment faire pour convertir & & ++ % & # 37 en page html à la chaîne normale?

&&++%&#37 

actually it is &&++%% 

ici est une table de SpecialCharacters, est là pour convertir cette chaîne de caractères spéciaux de toute API dans les normales?

http://www.degraeve.com/reference/specialcharacters.php

Writting tel code me semble pas assez sûr. Je pense qu'il doit y avoir quelques API

Existe-t-il une API existe dans MFC ou ATL? Merci beaucoup!

Répondre

0

Vous recherchez 'URLDecode'. Il n'est pas implémenté dans MFC - tout le monde a ses propres solutions. Essayez celui-ci:

std::string UriDecode(const std::string & sSrc) 
{ 
    // Note from RFC1630: "Sequences which start with a percent 
    // sign but are not followed by two hexadecimal characters 
    // (0-9, A-F) are reserved for future extension" 

    const unsigned char * pSrc = (const unsigned char *)sSrc.c_str(); 
    const int SRC_LEN = sSrc.length(); 
    const unsigned char * const SRC_END = pSrc + SRC_LEN; 
    // last decodable '%' 
    const unsigned char * const SRC_LAST_DEC = SRC_END - 2; 

    char * const pStart = new char[SRC_LEN]; 
    char * pEnd = pStart; 

    while (pSrc < SRC_LAST_DEC) 
    { 
     if (*pSrc == '%') 
     { 
     char dec1, dec2; 
     if (-1 != (dec1 = HEX2DEC[*(pSrc + 1)]) 
      && -1 != (dec2 = HEX2DEC[*(pSrc + 2)])) 
     { 
      *pEnd++ = (dec1 << 4) + dec2; 
      pSrc += 3; 
      continue; 
     } 
     } 

     *pEnd++ = *pSrc++; 
    } 

    // the last 2- chars 
    while (pSrc < SRC_END) 
     *pEnd++ = *pSrc++; 

    std::string sResult(pStart, pEnd); 
    delete [] pStart; 
    return sResult; 
} 
+0

Il semble répondre à une autre question? Encodage d'URL. Je veux juste convertir & Amp & &, & # 37 en%, etc. C'est un caractère spécial html – user25749