// Example file contents
NSString *fileContents = @"row1, row2, row3, row4, row5";
// Separate the titles into an array
NSMutableArray *titles = [[fileContents componentsSeparatedByString:@", "] mutableCopy];
// Remove row3 (at index 2 because indexes start from 0
[titles removeObjectAtIndex:2];
// Combine the array back into a string
NSString *result = [titles componentsJoinedByString:@", "];
// Log the result for debugging
NSLog(@"%@", result);
打印:row1, row2, row4, row5
此示例代碼創建一個字符串,使L ooks像你的文本文件,將它拆分成一個數組,刪除一個索引,然後將修改後的數組合併成一個字符串。
希望你會發現一些有用的代碼(我收集你會已經有一些或類似的使用)。
但是由於我不知道對象的索引,它必須與行號相同 – Alessandro
如果使用'tableView:didSelectRowAtIndexPath:'委託方法,只需使用'indexPath.row'來獲取所選行的索引。 – Greg