您的位置:首页 > 其它

2. 给定一个图片文件名,判断字符串中是否以“png”结尾,如果是就替换成“jpg”,如果不是,就拼接”.jpg”。

2014-08-07 23:13 525 查看
<span style="font-size:24px;">NSString *str4 = [[NSString alloc]  initWithFormat:@"http://www.baidu.com"];
BOOL isSuffix = [str4 hasSuffix:@"png"];
NSLog(@"isSuffix = %d", isSuffix);
if (isSuffix == 1) {
NSString *newStr1 = [str4 stringByReplacingOccurrencesOfString:@"png" withString:@"jpg"];
NSLog(@"%@",newStr1);
}else {
NSString *newStr2 = [str4 stringByAppendingFormat:@".jpg"];
NSLog(@"%@", newStr2);

}
</span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐