jump to navigation

NSASCIIStringEncoding breaks July 31, 2009

Posted by Ameya in iPhone.
Tags: , , , ,
trackback

It is possible that [subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding], may return null, if subject contains ASCII charter out side 0 to 127.

NSString *mailString = [NSString stringWithFormat:@"mailto :? to=%@&subject=%@&body=%@",
[to stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subject stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[body stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailString]];


To stop this we can use an simple filter like.
-(NSString *)replaceLatin :( NSString *)string{

return [[[[[[[[[[[[string stringByReplacingOccurrencesOfString:@"–" withString:@""] stringByReplacingOccurrencesOfString:@”—” withString:@”"] stringByReplacingOccurrencesOfString:@”¡” withString:@”"] stringByReplacingOccurrencesOfString:@”¿” withString:@”"] stringByReplacingOccurrencesOfString:@””” withString:@”"] stringByReplacingOccurrencesOfString:@”“” withString:@”"] stringByReplacingOccurrencesOfString:@”\”" withString:@”"] stringByReplacingOccurrencesOfString:@”‘” withString:@”"] stringByReplacingOccurrencesOfString:@”’” withString:@”"] stringByReplacingOccurrencesOfString:@”‘” withString:@”"] stringByReplacingOccurrencesOfString:@”«” withString:@”"] stringByReplacingOccurrencesOfString:@”»” withString:@”"];
}

Comments»

1. Bill Bartmann - September 1, 2009

Excellent site, keep up the good work


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.