This is my string.
NSString *str=@"A & B";
now i am converting it to NSUTF8StringEncoding.
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"str: %@", str);
space is replaced with %20 but & is not replaced with %26.
nslog show
str: A%20&%20B
This is also not working
NSString *str=@"(A) & (B)";
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"str: %@", str);
nslog show
str: (A)%20&%20(B)
I need this because i have to pass this as parameter value in webservice. Anybody have idea for this. Please help me for this issue. Nice answer will be appreciated
You can use CFURLCreateStringByAddingPercentEscapes()
to do that:
NSString *string = ...;
NSString *encodedString = CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)string, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), kCFStringEncodingUTF8));