识别iphone中两个字符串之间的字符串

时间:2012-06-19 13:29:34

标签: iphone

  

可能重复:
  retrieving the substring based on condition from a string in iphone

我是iphone的新手。我遇到了一些问题,我在xmlformat中有一个表示某个网站(http://www.audiotreasure.com/indexKJV.htm)源代码的字符串

请查看上述网站的视图来源,查看源代码是我现在的字符串

在上面的字符串中,我想搜索以(href =“)开头并以(.zip)结尾的字符串之间的字符串,然后我们得到这两个字符串之间的所有字符串,之后我必须放置所有这些字符串都成了数组..

如果有任何人知道这一点怎么可能请一步一步解释这个并帮助我......

1 个答案:

答案 0 :(得分:1)

使用NSRegularExpression:

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"href=\"(.*)\.zip\"" options:NSRegularExpressionCaseInsensitive error:&error];

NSRange rangeOfFirstMatch = [regex rangeOfFirstMatchInString:yourText options:0 range:NSMakeRange(0, [yourText length])];

if (!NSEqualRanges(rangeOfFirstMatch, NSMakeRange(NSNotFound, 0))) {

    NSString *substringForFirstMatch = [yourText substringWithRange:rangeOfFirstMatch];
    NSLog(@"Extracted URL: %@",substringForFirstMatch);
}
相关问题