识别iphone中两个字符串之间的字符串 [英] Identifying the string in between two strings in iphone

查看:110
本文介绍了识别iphone中两个字符串之间的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

根据iphone中字符串的条件检索子字符串

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

I am new to iphone.I am struck in some issue that is,I have one string which represents the source code of some website(http://www.audiotreasure.com/indexKJV.htm) in the xmlformat

请查看上面网站的查看源,查看源代码是我现在的字符串

please see the view source of the above website that view source is my present string right now

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

In the above string I want to search the strings in between the strings which starts with (href =") and ends with (.zip) then we get all the strings in between these two strings and after that i have to place all those strings into an array..

如果a ny身体知道这个请一步一步解释这个并帮助我......

how it is possible if any body know this please explain this in step by step procedure and help me......

推荐答案

使用NSRegularExpression:

Use a 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);
}

这篇关于识别iphone中两个字符串之间的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆