iOS 擷取字串中兩個指定字串中間的字串

weixin_33924312發表於2017-06-20
- (void)viewDidLoad {
    [super viewDidLoad];
    NSString *string = @"<a href=\"http\">這是要擷取的內容</a>";
    NSRange startRange = [string rangeOfString:@"\">"];
    NSRange endRange = [string rangeOfString:@"</"];
    NSRange range = NSMakeRange(startRange.location + startRange.length, endRange.location - startRange.location - startRange.length);
    NSString *result = [string substringWithRange:range];
    NSLog(@"%@",result);
}

相關文章