0

As you know no URL contain a space between the word of there parameters and I want to pass MyString=@"hello every body" to my URL parameters, like this

[@"http://www.site.com/index.php?contenu=" stringByAppendingString:MyString];

And I don't know how I can convert MyString to a valid format for URL

iPatel
  • 46,010
  • 16
  • 115
  • 137
kokio
  • 53
  • 7

5 Answers5

1

Try with Following Code :

NSString *urlString = [NSString stringWithFormat:@"http://www.site.com/index.php?contenu=%@", MyString];
NSURL *myURL = [NSURL URLWithString:[urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

AlsoRead This Official Documentation about String Format Specifiers.

iPatel
  • 46,010
  • 16
  • 115
  • 137
0

Why don't you do the whole thing in this manner ?

First make a string with parameter in the following way :

NSString *stringURL = [NSString stringWithFormat:@"http://www.site.com/index.php?contenu=%@",MyString];

Convert the string to URL :

NSURL *url = [NSURL URLWithString:MyString];

Now you can use that url safely.

Rajan Balana
  • 3,775
  • 25
  • 42
0

for space u should use %20, for that use url encode Try This

Or use stringByReplacingPercentEscapesUsingEncoding

Community
  • 1
  • 1
Sachin
  • 333
  • 1
  • 4
  • 19
0

try like this ,

NSString *encodedUrlString = [urlString stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
Balu
  • 8,470
  • 2
  • 24
  • 41
0

You can try this by replacing space with %20

Code ::

NSString *reqString;
reqString = [NSString stringWithFormat:@"%s%@", Server_URL, your_paramater];
reqString = [reqString stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSLog(@"... URL :::: %@", reqString);

Try it once, It may be help you.

Thanks.

Manann Sseth
  • 2,745
  • 2
  • 30
  • 50