(C) URL Encoding and Decoding
Demonstrates URL encoding and decoding.
#include <C_CkStringBuilder.h>
void ChilkatSample(void)
{
const char *s;
HCkStringBuilder sb;
BOOL success;
const char *sEncoded;
int numReplaced;
// To URL encoding a string:
s = "Why a > b?";
sb = CkStringBuilder_Create();
success = CkStringBuilder_Append(sb,s);
// URL encode the string.
CkStringBuilder_Encode(sb,"url","utf-8");
// Show the URL encoded string:
sEncoded = CkStringBuilder_getAsString(sb);
printf("%s\n",sEncoded);
// The result is: Why%20a%20%3E%20b%3F
// If you prefer "+" instead of "%20" for SPACE chars:
numReplaced = CkStringBuilder_Replace(sb,"%20","+");
printf("%s\n",CkStringBuilder_getAsString(sb));
// Output is: Why+a+%3E+b%3F
// To decode:
CkStringBuilder_Decode(sb,"url","utf-8");
printf("%s\n",CkStringBuilder_getAsString(sb));
// Result is: Why a > b?
CkStringBuilder_Dispose(sb);
}
|