Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to encode and decode NSString

    • 0
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 954
    Comment on it

    Following method will encode and decode NSString. Characters to leave unescaped (NULL = all escaped sequences are replaced).

    - (NSString *)URLEncodedString {
        CFStringRef url = CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)self, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8); // for some reason, releasing this is disasterous
        NSString *result = (NSString *)url;
        [result autorelease];
        return result;
    }
    
    - (NSString *)URLDecodedString {
        CFStringRef url = CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)self, CFSTR(""), kCFStringEncodingUTF8);
        NSString *result = (NSString *)url;
        [result autorelease];
        return result;
    }
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: