2009-11-13 4 views
1

내가 MFC에서 작업 및 HTML에 다음 코드를 얻을 : 여기변환하는 방법 & & ++ % & html 페이지의 # 37을 (를) 정상적인 문자열로 변환 하시겠습니까?

&&++%&#37 

actually it is &&++%% 

specialcharacters의 테이블입니다,이 정상적인 사람으로이 특별한 문자열을 변환 할 수있는 API의?

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

는 코드를을 writting 자신은 충분히 안전하지 보인다. API가 있어야한다고 생각합니다.

MFC 또는 ATL에 API가 있습니까? 많은 감사합니다!

답변

0

'URL 코드'를 찾고 있습니다. MFC에는 구현되어 있지 않습니다. 모두가 독자적인 솔루션을 가지고 있습니다. 이 중 하나를 시도해보십시오 :

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

다른 질문에 대한 답변으로 보입니까? URL 인코딩. & amp;를 &, & # 37 %로 변환하고 싶습니다. 그것은 html 특수 문자입니다. – user25749