编码撇号目标c的字符串函数

时间:2013-05-08 06:11:52

标签: ios objective-c xcode character-encoding nsstring

http://php.weenggs.com/scrap/service.php?op=search&search_term=Crabbie的 - >我的api http://php.weenggs.com/scrap/service.php?op=search&search_term=Crabbie%20 - >想要这样

[myStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

将空格转换为%20,就像我想要转换为%20一样。

1 个答案:

答案 0 :(得分:0)

尝试使用stringByReplacingOccurrencesOfString方法,

此处用's

替换%20的出现
    str=[str stringByReplacingOccurrencesOfString:@"'s" withString: @"%20"];


NSString *str=@"http://php.weenggs.com/scrap/service.php?op=search&search_term=Crabbie's";
    str=[str stringByReplacingOccurrencesOfString:@"'s" withString: @"%20"];
    NSLog(@"%@",str);

O / P: -

http://php.weenggs.com/scrap/service.php?op=search&search_term=Crabbie%20