tags:

views:

115

answers:

4

I have an Image named "John and Tony.png".When I tried to download the image from my code with this name via an http request no image is shown.But if I remove the space between the words like "JohnandTony.png" then there is no problem to download the image.But I can't want to remove the spaces.Is there any way to do that?

Thanx

A: 

Can you give some sample code?

Also why don't you want spaces in the name?

matkins
NSString *imagestring=[NSString stringWithFormat:@"http://28.162.10.2/images/ohn and Tony.png"];UIImage *image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imagestring]]];nowPlayingImage.image=image;Because one can save the image by putting an space in between the name of the image.
XcoderMi2
+2  A: 

you need to escape the spaces with "%20"s.

NSString *imageStr = @"http://whatever.com/John and Tony.png";
NSString *imageStrEscaped = [urlStr stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

Then use this string as the url.

Joe Cannatti
A: 

Your URL doesn't must contain spaces. If you want let this name, you must use the %20 to replace the spaces like that:

"John%20and%20Tony.png"

Yannick L.
A: 

I think you are creating the imagestring the wrong way. Try the following:

NSString *imagestring = @"28.162.10.2/images/John and Tony.png";  
imagestring = [imagestring stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
Shingoo
Thanx guys for your replies,it is working now.
XcoderMi2