我有一個NSMutableArray的這樣的創建刪除的對象..如何從NSMutableArray的是hasSufix
NSString *urlString = [NSString stringWithFormat:@"%@", @"http://192.168.43.1:8080/mediaListFull"];
NSURL *stringURL = [NSURL URLWithString:urlString];
NSData *urlData = [NSData dataWithContentsOfURL:stringURL];
NSString *stringFromData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
/// Populating the urlArray "tableView" from stringFromData..
urlArray = [[NSMutableArray alloc]init];
urlArray = [[stringFromData componentsSeparatedByString:@"\n"]mutableCopy];
我想刪除有後綴JPG格式的所有字符串我使用這個代碼,試圖做到這一點,但它不管用。
NSString *stringToRemove = @".jpg";
for (int i = 0; i < urlArray.count; i ++) {
NSLog(@"The UrlArray has this in it %@",[urlArray objectAtIndex:i]);
NSString *temp = [NSString stringWithFormat:@"%@",[urlArray objectAtIndex:i]];
if ([temp hasSuffix:stringToRemove]) {
[urlArray removeObjectAtIndex:i];
}
}
所以當我登錄數組時,它仍然包含所有的.jpg文件。 任何幫助非常感謝。
FYI the array looks like this.
2016年7月28日10:00:22.087 ImageURLDownLoad [716:232095]的urlArray具有此在它(
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LivePic-19700101_001527.jpg
",
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LivePic-19700101_001533.jpg
",
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LivePic-19700101_000600.jpg
",
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LivePic-19700101_000605.jpg
",
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LivePic-19700101_000610.jpg
",
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LivePic-19700101_000632.jpg
",
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LivePic-19700101_000642.jpg
",
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LivePic-19700101_000652.jpg
",
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LiveVid-19700101_000544.mp4
",
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LiveVid-19700101_001101.mp4
",
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LiveVid-19700101_001129.mp4
",
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LiveVid-19700101_001429.mp4
",
"http://192.168.43.1:8080/mediaResponse/?fileName=/storage/emulated/0/liveMedia/LivePic-19700101_004538.mp4"
)
問候 JZ
'[urlArray filterUsingPredicate:[NSPredicate predicateWithFormat: 「JPG」 @ 「SELF的endsWith並[c]%@」,@]'?而且'urlArray'的alloc/init是無用的,因爲你剛分配它。 – Larme
我試過這個「[urlArray filterUsingPredicate:[NSPredicate predicateWithFormat:@」SELF ENDSWITH [c]%@「,@」。jpg「]」,它刪除數組的所有內容。 –
這是因爲看起來每個URL末尾都有一個額外的字符。而且我讓謂詞只用.jpg保留,它應該有一個NOT。 – Larme