|Apr 8, 2009, 03:12 PM||#1|
Ampersand cutting off NSString?
I have an NSString with an ampersand (&) in it being sent to the Mail app and it keeps cutting off the rest of my string. I've tried looking for a solution and using &&, %& and /ampersand but none seem to work. This is making me pull my hair out!
Edit: This should have gone into the iPhone forum but I'm sure the issue is the same.
Last edited by kwjohns; Apr 8, 2009 at 03:23 PM.
|Apr 8, 2009, 03:42 PM||#2|
You need to encode the & since normally it's used to separate parameters in the URL. Normally NSString's stringByAddingPercentEscapesUsingEncoding method would work in most cases, but here you need to use Core Foundation to encode the ampersand:
NSString *body = @"This is an ampersand & test."; CFStringRef encodedBody = CFURLCreateStringByAddingPercentEscapes(NULL, (CFStringRef)body, NULL, CFSTR("&"), kCFStringEncodingUTF8); NSString *urlString = [NSString stringWithFormat:@"mailto:firstname.lastname@example.org?body=%@", (NSString *)encodedBody]; CFRelease(encodedBody); NSURL *url = [NSURL URLWithString:urlString];
|Apr 8, 2009, 04:04 PM||#3|
|Thread Tools||Search this Thread|
|thread||Thread Starter||Forum||Replies||Last Post|
|php mysql = NSString||IDMah||iPhone/iPad Programming||9||Dec 20, 2013 02:35 PM|
|C Function from NSString?||ArtOfWarfare||Mac Programming||20||Jun 16, 2013 11:55 AM|
|NSString to NSSize||larswik||Mac Programming||1||May 28, 2013 07:54 PM|
|NSString and NSRange Tutorials||nashyo||iPhone/iPad Programming||3||Aug 24, 2012 10:08 PM|
|(NSString*) ??||thedon1||iPhone/iPad Programming||6||Jul 2, 2012 08:52 PM|
All times are GMT -5. The time now is 10:39 AM.