URLEncode With Objective C - The OAUTH Way


Coming from a PHP background, we should all be thankful to rawurlencode() from PHP! Here’s an Objective C version with OAUTH v1.0a requirements.

- (NSString *)urlencode:(NSString *)text {
    NSString *temp = @"";

    for(int i=0, max=[text length]; i=0x30 && b<=0x39) ||
           (b>=0x41 && b<=0x5A) ||
           (b>=0x61 && b<=0x7A)
            ) {
            temp = [temp stringByAppendingFormat:@"%c", t];
        } else {
            temp = [temp stringByAppendingString:@"%"];
            if (b <= 0xf) temp = [temp stringByAppendingString:@"0"];
            temp = [NSString stringWithFormat:@"%@%X", temp, b];
        }
    }
    
    return temp;
}