(Unicode C) URL Encoding and Decoding
Demonstrates URL encoding and decoding.
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
const wchar_t *s;
HCkStringBuilderW sb;
BOOL success;
const wchar_t *sEncoded;
int numReplaced;
// To URL encoding a string:
s = L"Why a > b?";
sb = CkStringBuilderW_Create();
success = CkStringBuilderW_Append(sb,s);
// URL encode the string.
CkStringBuilderW_Encode(sb,L"url",L"utf-8");
// Show the URL encoded string:
sEncoded = CkStringBuilderW_getAsString(sb);
wprintf(L"%s\n",sEncoded);
// The result is: Why%20a%20%3E%20b%3F
// If you prefer "+" instead of "%20" for SPACE chars:
numReplaced = CkStringBuilderW_Replace(sb,L"%20",L"+");
wprintf(L"%s\n",CkStringBuilderW_getAsString(sb));
// Output is: Why+a+%3E+b%3F
// To decode:
CkStringBuilderW_Decode(sb,L"url",L"utf-8");
wprintf(L"%s\n",CkStringBuilderW_getAsString(sb));
// Result is: Why a > b?
CkStringBuilderW_Dispose(sb);
}
|