[英]IOS: stringByReplacingOccurrencesOfString don't work
文件路径:/var/mobile/Applications/BA7AE6F8-C7EA-4601-A5F4-30E3C57FE948/Documents/photo2.jpg照片编号:/ var / mobile / Applications / BA7AE6F8-C7EA-4601-A5F4-30E3C57FE948 / Documents / 2
索引= 2;
NSString *nextSequentialFile =
[filePath stringByReplacingOccurrencesOfString:photoNumber
withString:[NSString stringWithFormat:@"%d", index+1]
options:NSBackwardsSearch
range:NSMakeRange(0, filePath.length)];
结果是下一个序列:/var/mobile/Applications/BA7AE6F8-C7EA-4601-A5F4-30E3C57FE948/Documents/photo2.jpg
为什么?
它必须是/photo3.jpg
filepath
不包含photonumber
,因此没有可替换的内容。 请注意, photonumber
/Documents/2
filepath
包含/Documents/photo2.jpg
时, photonumber
以/Documents/2
/Documents/photo2.jpg
。
需要将photonumber
更改为/Documents/photo2
结尾,并将替换字符串更改为[NSString stringWithFormat:@"/photo%d", index+1]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.