iOS字符串拼接 stringByAppendingString:与 stringByAppendingPathComponent:
2017-11-24 14:38
302 查看
之前的旧项目,把功能模块移植到另一个应用中,结果在图片加载的时候,始终加载不到图片,然后一路追查,查到了拼接的图片地址上面,打印图片地址发下http://协议头少了个“/” , 项目中都是这样使用
拼接的网络地址,POST网络请求也没问题。唯独使用SDWebimage 进行图片加载时失败 ,因为协议头少了个 / 。(猜测stringByAppendingPathComponent:方法是会进行以单 / 替换字符串中连在一起的多个 // )
打印结果:
2017-11-24 14:19:48.607 Switch[59129:2841826] ===https://123.21.54.1/health/uiiddd/3323/justtry
2017-11-24 14:19:48.608 Switch[59129:2841826] ===https:/123.21.54.1/health/uiiddd/3323/justtry
2017-11-24 14:33:38.935 Switch[59409:2855959] ===https:/123.21.54.1/health/uiiddd/3323/justtry
stringByAppendingPathComponent:
拼接的网络地址,POST网络请求也没问题。唯独使用SDWebimage 进行图片加载时失败 ,因为协议头少了个 / 。(猜测stringByAppendingPathComponent:方法是会进行以单 / 替换字符串中连在一起的多个 // )
NSString *testStr = @"https://123.21.54.1/health/uiiddd/3323"; NSString *str = [testStr stringByAppendingString:@"/justtry"]; NSString *comStr = [testStr stringByAppendingPathComponent:@"justtry"]; NSLog(@"===%@",str); NSLog(@"===%@",comStr); NSString *comStr2 = [testStr stringByAppendingPathComponent:@"///justtry"]; NSLog(@"===%@",comStr2);
打印结果:
2017-11-24 14:19:48.607 Switch[59129:2841826] ===https://123.21.54.1/health/uiiddd/3323/justtry
2017-11-24 14:19:48.608 Switch[59129:2841826] ===https:/123.21.54.1/health/uiiddd/3323/justtry
2017-11-24 14:33:38.935 Switch[59409:2855959] ===https:/123.21.54.1/health/uiiddd/3323/justtry
相关文章推荐
- iOS中stringByAppendingString 和 stringByAppendingPathComponent 的区别
- stringByAppendingString, stringByAppendingPathComponent, stringByAppendingPathExtension
- stringByAppendingPathComponent和stringByAppendingString的区别
- stringByAppendingPathComponent与stringByAppendingString区别
- stringByAppendingPathComponent和stringByAppendingString的区别
- stringByAppendingPathComponent和stringByAppendingString的区别
- stringByAppendingPathComponent、stringByAppendingString等语句的区别
- stringByAppendingPathComponent和stringByAppendingPathExtension区别
- stringByAppendingPathComponent和stringByAppendingString的区别
- stringByAppendingPathExtension拼接路径
- ios开发- 将字符串切割成数组 componentSeparatedByString
- stringByAppendingPathComponent和stringByAppendingString的区别
- stringByAppendingPathComponent及他的删除函数 等系列函数
- stringByAppendingPathComponent和stringByAppendingString的区别
- StringByAppendingPathComponent和stringByAppendingString的区别
- stringByAppendingPathComponent和stringByAppendingString的区别
- stringByAppendingString和stringByAppendingPathComponent
- stringByAppendingPathComponent和stringByAppendingString的区别
- [C/C++标准库]_[初级]_[构造文件路径(stringByAppendingPathComponent)]
- stringByAppendingPathComponent和stringByAppendingString 的区别