Sheehan Alam Sheehan Alam - 3 years ago 298
Objective-C Question

How can I parse the src property of an iframe tag in Objective-C?

I have the following string:

<iframe width="1280" height="720" src="" frameborder="0" allowfullscreen></iframe>

I'd like to pull out the src property, but not exactly sure how I would parse that in Objective-C?

Answer Source

This is ugly, but it works:

NSString* str = @"<iframe width=\"1280\" height=\"720\" src=\"\" frameborder=\"0\" allowfullscreen></iframe>";
str = [str substringFromIndex:[str rangeOfString:@"src=\""].location+[str rangeOfString:@"src=\""].length];
str = [str substringToIndex:[str rangeOfString:@"\""].location ];
NSLog(@"Str %@",str);

I tested it, and it outputs:

2012-08-17 09:16:55.285 TEST[24413:c07] Str
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download