如何用格式的字符串中的+替换空格

时间:2012-06-05 13:46:37

标签: ios xcode string replace space

  

可能重复:
  How do i replace spaces with +'s in Xcode

在这个字符串中我需要替换空格:

controller.body = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@@%@,%@", pinTitle.text, newlatLabel.text, newlogLabel.text];

2 个答案:

答案 0 :(得分:12)

像:

NSString *finalString = [controller.body stringByReplacingOccurrencesOfString:@" " withString: @"+"];

controller.body = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@@%@,%@", pinTitle.text, newlatLabel.text, newlogLabel.text];

NSString *finalString = [controller.body stringByReplacingOccurrencesOfString:@" " withString: @"+"];

controller.body = finalString;

答案 1 :(得分:1)

认为你正在寻找这个:

  NSString *finalString = [controller.body stringByReplacingOccurrencesOfString:@" " withString:@"+"];