Question

It bothers me a bit to ask you for help on a problem like this but I really need help...

I don't understand why but my NSURL ends with %20.

My code:

 NSString *imagestring = [NSString stringWithString:images];
        NSLog(@"String image : %@" , imagestring);
        NSURL *urlimage = [[NSURL alloc] initWithString:[imagestring stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
        NSLog(@"Url image:  %@" , urlimage);

Console output:

2014-05-02 20:52:03.453 Xbox One Sortie[1438:70b] String image : http://media.melty.fr/article-1488731-ajust_930/call-of-duty-ghosts.jpg 
2014-05-02 20:52:03.454 Xbox One Sortie[1438:70b] Url image:  http://media.melty.fr/article-1488731-ajust_930/call-of-duty-ghosts.jpg%20
Was it helpful?

Solution

%20 is nothing but white space.

Because of stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding you see space as %20.

If you have whitespace at the end, use below code to remove it.

NSString *string = @" this text has spaces before and after ";
NSString *trimmedString = [string stringByTrimmingCharactersInSet:
                              [NSCharacterSet whitespaceCharacterSet]];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top