文件路径:/var/mobile/Applications/BA7AE6F8-C7EA-4601-A5F4-30E3C57FE948/Documents/photo2.jpg photonumber:在/ var /移动/应用/ BA7AE6F8-C7EA-4601-A5F4-30E3C57FE948 /文档/ 2
index = 2;
NSString *nextSequentialFile =
[filePath stringByReplacingOccurrencesOfString:photoNumber
withString:[NSString stringWithFormat:@"%d", index+1]
options:NSBackwardsSearch
range:NSMakeRange(0, filePath.length)];
结果永远 nextsequenzial:/var/mobile/Applications/BA7AE6F8-C7EA-4601-A5F4-30E3C57FE948/Documents/photo2.jpg
为什么?
一定是/photo3.jpg
答案 0 :(得分:1)
filepath
不包含photonumber
,因此无需替换。请注意,photonumber
以/Documents/2
结尾,filepath
包含/Documents/photo2.jpg
。
photonumber
需要更改为/Documents/photo2
,并且替换字符串需要更改为[NSString stringWithFormat:@"/photo%d", index+1]
。