ios - 从 iPhone 中的字符串中获取子字符串

标签 ios objective-c nsstring nsrange

我有一个这样的字符串

<img alt=\"Marco Bueno\" src=\"http://u.goal.com/136600/136687_thumb.jpg\" style=\"float: left;margin:0 10px 10px 10px;\" title=\"Marco Bueno\" /><p style=\"float:left;\">Herrera is currently on national team duty representing the U-23 side that has already made history at the Toulon Tournament, while Bueno won the U-17 World Cup in 2011</p>

我想从此字符串中获取“src”( http://u.goal.com/136600/136687_thumb.jpg )。我怎样才能以动态的方式得到它。

谢谢!!

最佳答案

您可以使用这样的方式获取您的网址...

NSRange divRange = [dateString rangeOfString:@"src=\"" options:NSCaseInsensitiveSearch];
    if (divRange.location != NSNotFound)
    {
        NSRange endDivRange;

        endDivRange.location = divRange.length + divRange.location;
        endDivRange.length   = [dateString length] - endDivRange.location;
        endDivRange = [dateString rangeOfString:@".jpg" options:NSCaseInsensitiveSearch range:endDivRange];

        if (endDivRange.location != NSNotFound)
        {
            divRange.location += divRange.length;
            divRange.length  = endDivRange.location - divRange.location + endDivRange.length;


            NSLog(@"BinarySecurityToken : %@",[dateString substringWithRange:divRange]);
        }
    }

输出: http://u.goal.com/136600/136687_thumb.jpg

关于ios - 从 iPhone 中的字符串中获取子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16584812/

相关文章:

ios - 将NSString转换为NSDate

iphone - 您在哪里以编程方式在 UIView 中为 UILabels 设置文本?

ios - 方向问题 iOS 5

objective-c - 核心数据 - 将实体保存为 pList/字典

c# - 为类和协议(protocol)创建 Xamarin iOS 绑定(bind)

objective-c - 在多行中声明一个 NSString

objective-c - iOS 非导航栏基于导航和 View 交换

ios - 值应四舍五入到最接近的十分之一或最接近的四分之一

ios - Today Extension 更改后刷新应用程序上的 CoreData

objective-c - 如何在保留斯堪的纳维亚字母的同时一直为 SQLite 正确编码 NSString