Url 인코딩, 디코딩

url인코드 디코드하는 함수입니다.  별로 설명은 필요없을것 같아 생략하겠습니다... 출처는 codeproject입니다. 그럼^^

CString EnCodeStr(CString ToCode)
{
CString RetStr,AddStr;
int i,max;
unsigned short asc;
unsigned char c;
max = (unsigned int)ToCode.GetLength();
for(i=0;i<max;i++) {="" c="ToCode[i];" asc="c;//(unsigned" int)c;="" if(asc="">47 && asc<58)
{
RetStr+=c;//Interim[(int)i];
}
else if(asc>64 && asc<91)
{
RetStr+=c;//Interim[(int)i];
}
else if(asc>96 && asc<123)
{
RetStr+=c;//Interim[(int)i];
}
else if(asc==32)
{
RetStr+="+";
}
else
{
AddStr.Format("%%%2x" ,asc);
int iv = (int)AddStr.GetAt(1);
if((int)AddStr.GetAt(1)==32)
{
AddStr.SetAt(1,'0');
}
RetStr+=AddStr;
}
}
return RetStr;
}

CString DeCodeStr(CString ToCode)
{
    CString RetStr,AddStr;
    int i,max;
    unsigned short asc;
    unsigned char c;
    max = (unsigned int)ToCode.GetLength();
    for(i=0;i<max;)
    {
        c = ToCode[i];
        asc = c;//(unsigned int)c;
        if(asc==37)
        {
            AddStr=ToCode.Mid(i+1,2);
            i+=3;
            sscanf((LPCTSTR)AddStr,"%2x",&asc);
            RetStr+=(char)asc;
        }
        else if(asc==43)
        {
            RetStr += ' ';
            i++;
        }
        else
        {
            RetStr += c;
            i++;
        }
    }
    return RetStr;
}

'NIght.. > C++API+MFC' 카테고리의 다른 글

HDC 에서 CDC로 변환하는 방법  (0) 2008/10/30
char 을 WCHAR 로, WCHAR 을 char 로  (0) 2008/10/30
Url 인코딩, 디코딩  (0) 2008/10/30
to Unicode to Ansi  (0) 2008/10/30
ShellExecute 사용예  (0) 2008/10/30
RegEnumValue, Key 사용예  (0) 2008/10/30

Write your message and submit