在两个已知字符串之间搜索一个字符串 [英] Search for a string between two known strings

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

问题描述

我有一个包含以下内容的字符串:

I have a String with this content:

href="http://www.website.com/" /> [...] [...]

我只想获取字符串的中心部分.如何获得@"href ="和@""/>"

I just want to get the central part of the string. How is it possible to get the part between @"href="" and @"" />"

注意:即使看起来像xml代码,它也位于NSString内部.

Note: Even if it looks like xml-code, it is inside of a NSString.

推荐答案

我明白了!

这是代码(写得不太好):

This is the code (not very nice written):

NSRange rr2 = [content rangeOfString:@"href=\""];
    NSRange rr3 = [content rangeOfString:@"\" />"];
    int lengt = rr3.location - rr2.location - rr2.length;
    int location = rr2.location + rr2.length;
    NSRange aa;
    aa.location = location;
    aa.length = lengt;
    theString = [theString substringWithRange:aa];

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

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