簡體   English   中英

iOS:stringByReplacingOccurrencesOfString不起作用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM