Reputation: 186
i am trying to get the path to a certain file
and then open it in a webview. so i need to replace each space by '%20'
NSString *test=@"filename";
NSString *finalPath12 = [test stringByAppendingString:@".pdf"];
NSString *path1 = [[NSBundle mainBundle] bundlePath];
NSString *finalPath1 = [path1 stringByAppendingPathComponent:finalPath12];
NSString *file =@"file://";
NSString *htmlfilename1 = [file stringByAppendingString:finalPath1];
NSString *pathtofile = [htmlfilename1 stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
any string is working except @"%20".
this works perfectly for exemple:
NSString *pathtofile = [htmlfilename1 stringByReplacingOccurrencesOfString:@" " withString:@"string"];
but i need the @"%20". What am i missing ? Thanks
Upvotes: 1
Views: 54
Reputation: 122391
There is already [NSString stringByAddingPercentEscapesUsingEncoding:]
(reference) for that very purpose.
However in your case, as you want a URL, you can replace all the lines in your question with:
NSURL *url = [[NSBundle mainBundle] urlForResource:@"filename" withExtension:@"pdf"];
Upvotes: 3
Reputation: 46543
You need to use @"%%20"
.
As first % is treated as escape/wild character.
Or use
stringByAddingPercentEscapesUsingEncoding:
Upvotes: 1