公司项目中一直很2,用替换的方式来解决这个问题,一直觉得肯定有更好的方法。刚刚看了偶然看到一段代码,debug了一下,应该就是这个。
先把结果放上来
(lldb) po addressText
$0 = 0x00004730 1 Infinite Loop, Cupertino, CA 95014
(lldb) po addressText
$1 = 0x09639280 1%20Infinite%20Loop,%20Cupertino,%20CA%2095014
(lldb)
// Where is Apple on the map anyway?
NSString* addressText = @"1 Infinite Loop, Cupertino, CA 95014";
// URL encode the spaces
addressText = [addressText stringByAddingPercentEscapesUsingEncoding: NSASCIIStringEncoding];
NSString* urlText = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", addressText];