0

I want to ask if I want to create a NSString, such as

for ( int i=1; i<=10; i++) {
    NSString *picURLstring = [NSString stringWithFormat:@"http://localhost/Testing/files/Demo Presentation/Slide%d.JPG", i] ;
...
}

This is part of my code, so that I can later get the URL of 10 images. Then I use this URL to download the images from my server, but it seems dont work. But while I change the file in my server from "Demo Presentation" to "DemoPresentation", also the Xcode statement to:

    for ( int i=1; i<=10; i++) {
    NSString *picURLstring = [NSString stringWithFormat:@"http://localhost/Testing/files/DemoPresentation/Slide%d.JPG", i] ;
...
}

It works! It can download the images I need from my server. So may I ask how to implement a space inside a string? I tried to use %20, thus "Demo%20Presentation" in the string, but it still not working, please help.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
Chow Cena
  • 3
  • 5
  • Can you elaborate on what goes wrong? What do you mean by "no string is got after my testing"? – sjs Jun 25 '13 at 05:31
  • How do you use this string afterwards? – FreeNickname Jun 25 '13 at 05:33
  • 2
    NSString *encodedString = [myString stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; try like this For your case..... for ( int i=1; i<=10; i++) { NSString *picURLString = [[NSString stringWithFormat:@"http://localhost/Testing/files/Demo Presentation/Slide%d.JPG", i] stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]; } – Arun Jun 25 '13 at 05:35
  • Sorry about my bad english, I edited the question to elaborate the error. – Chow Cena Jun 25 '13 at 05:38
  • @ChowCena are you tried my comment – Arun Jun 25 '13 at 05:40
  • @Spynet trying, thanks for your help first – Chow Cena Jun 25 '13 at 05:42
  • Thanks @Spynet , it works perfectly now with no error, thanks for the help! Really. – Chow Cena Jun 25 '13 at 05:46

1 Answers1

2

try this:

for ( int i=1; i<=10; i++) {
    NSString *picURLstring = [NSString stringWithFormat:@"http://localhost/Testing/files/Demo Presentation/Slide%d.JPG", i] ;
    NSURL *url = [NSURL URLWithString:[picURLstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    //use url ...
}
DharaParekh
  • 1,730
  • 1
  • 10
  • 17