<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”。
最新推荐文章于 2024-01-09 16:29:15 发布