Sample code for 30+ languages & platforms
Objective-C

URL Encoding and Decoding

See more Encryption Examples

Demonstrates URL encoding and decoding.

Chilkat Objective-C Downloads

Objective-C
#import <NSString.h>
#import <CkoStringBuilder.h>

BOOL success = NO;

// To URL encoding a string:
NSString *s = @"Why a > b?";

CkoStringBuilder *sb = [[CkoStringBuilder alloc] init];
success = [sb Append: s];

// URL encode the string.
[sb Encode: @"url" charset: @"utf-8"];

// Show the URL encoded string:
NSString *sEncoded = [sb GetAsString];
NSLog(@"%@",sEncoded);

// The result is:  Why%20a%20%3E%20b%3F

// If you prefer "+" instead of "%20" for SPACE chars:
int numReplaced = [[sb Replace: @"%20" replacement: @"+"] intValue];
NSLog(@"%@",[sb GetAsString]);

// Output is:   Why+a+%3E+b%3F

// To decode:
[sb Decode: @"url" charset: @"utf-8"];
NSLog(@"%@",[sb GetAsString]);

// Result is: Why a > b?