<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>2. 给定一个图片文件名,判断字符串中是否以“png”结尾,如果是就替换成“jpg”,如果不是,就拼接”.jpg”。
最新推荐文章于 2022-08-02 17:28:01 发布
本文探讨了如何在Objective-C中使用字符串操作方法,包括字符串查找、替换和追加操作,以及如何根据需要将文件路径从一种文件扩展名转换为另一种。
3152

被折叠的 条评论
为什么被折叠?



