Utilisation: stringByAddingPercentEscapesUsingEncoding:
Renvoie une représentation du récepteur en utilisant un codage donné pour déterminer le pour cent échappe nécessaire pour convertir le récepteur dans une chaîne d'URL juridique.
-(NSString *)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding
Une représentation du récepteur en utilisant le codage pour déterminer le pour cent échappe nécessaire pour convertir le récepteur dans une chaîne d'URL juridique. Retourne nil si le codage ne peut coder un caractère particulier
Ajouté par demande par @rule
NSString* urlText = @"70.84.58.40/projects/igolf/TipThumb/GOLF 58B.jpg";
NSString* urlTextEscaped = [urlText stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString: urlTextEscaped];
NSLog(@"urlText: '%@'", urlText);
NSLog(@"urlTextEscaped: '%@'", urlTextEscaped);
NSLog(@"url: '%@'", url);
sortie NSLog:
urlText: '70.84.58.40/projects/igolf/TipThumb/GOLF 58B.jpg'
urlTextEscaped: '70.84.58.40/projects/igolf/TipThumb/GOLF%2058B.jpg'
url: '70.84.58.40/projects/igolf/TipThumb/GOLF%2058B.jpg'
question brillante, trébuché sur ce par hasard en ayant un problème similaire. –