類似Java的lastIndexOf
[@"abc def ghi abc def ghi" rangeOfString:@"abc" options:NSBackwardsSearch];
會回傳最後一個符合的NSRange
example:
NSString *file = @"/document/test/folder/file.txt”;
NSString *onlyPath = [file substringToIndex:[file rangeOfString:@"/" options:NSBackwardsSearch].location];
onlyPath = /document/test/folder
[@"abc def ghi abc def ghi" rangeOfString:@"abc" options:NSBackwardsSearch];
會回傳最後一個符合的NSRange
example:
NSString *file = @"/document/test/folder/file.txt”;
NSString *onlyPath = [file substringToIndex:[file rangeOfString:@"/" options:NSBackwardsSearch].location];
onlyPath = /document/test/folder
留言
張貼留言