如何从此字符串中获取URL

时间:2012-12-12 12:10:26

标签: iphone objective-c ios xcode cocoa-touch

如何从以下

获取网址
  

[bpfb_link url ='http://www.abcd.com/'title ='abcd Technologies ::   主页'image ='http://www.abcd.com//images/itwall_b1.gif']                   [/ bpfb_link]

以上链接i retrievedphp方法转换为xml。如何从formatted url获得above tag。 我想用componentsseperatedBystring来获取字符串,但格式每次都会改变。 我正在执行以下操作以删除不需要的字符串

NSRange rangeLink = [[[arrUpdates valueForKeyPath:@"content"]objectAtIndex:intIndexPath] rangeOfString:@"bpfb_link"];
            if (rangeLink.location != NSNotFound) 
            {

            NSArray *arrNewLink=[[[arrUpdates valueForKeyPath:@"content"]objectAtIndex:intIndexPath] componentsSeparatedByString:@"["];
                NSLog(@"arrNewLink  %@",[arrNewLink objectAtIndex:0]);
                //[[arrNewLink objectAtIndex:1] componentsSeparatedByString:@"]"];

                NSArray *arrEditedLinks=[[arrNewLink objectAtIndex:1]componentsSeparatedByString:@"]"];
                 NSLog(@"arrEditedLinks  %@",[arrEditedLinks objectAtIndex:1] );
}

请帮帮我

1 个答案:

答案 0 :(得分:0)

如果您的回答是不变的,那么您可以这样做

NSString *temp=@"[bpfb_link url='http://www.abcd.com/' title='abcd Technologies : : Home Page' image='http://www.abcd.com//images/itwall_b1.gif'] [/bpfb_link]";
    NSArray *arr=[[NSArray alloc]init];
    arr=[temp componentsSeparatedByString:@"'"];
    NSLog(@"arr %@",[arr objectAtIndex:1]);

out put is-- http://www.abcd.com/