iOS字符串拼接 stringByAppendingString:与 stringByAppendingPathComponent:

         之前的旧项目,把功能模块移植到另一个应用中,结果在图片加载的时候,始终加载不到图片,然后一路追查,查到了拼接的图片地址上面,打印图片地址发下http://协议头少了个“/” , 项目中都是这样使用
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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值