我有一个包含以下内容的字符串:
href="http://www.website.com/" /> [...] [...]
我只想得到字符串的中心部分。怎么可能得到@"href=""和@""/>"之间的部分
注意:即使它看起来像 xml-code,它也包含在 NSString 中。
最佳答案
我知道了!
这是代码(写得不是很好):
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];
关于objective-c - 在两个已知字符串之间搜索一个字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2493153/