我想在我的样式标签之间使用数组获取样式,但我得到空数组。
NSScanner* scanners = [NSScanner scannerWithString:replacement];
NSMutableArray *style = [[NSMutableArray alloc] init];
[scanner scanUpToString:@"<style" intoString:nil];
while (![scanner isAtEnd]) {
[scanners scanUpToString:@">" intoString:nil];
[scanners scanString:@">" intoString:nil];
NSString * text = nil;
[scanners scanUpToString:@"</style>" intoString:&text];
if (text) { // if html contains empty paragraphs <p></p>, text could be nil
[style addObject:text];
NSLog(@"%@",style);
}
[scanners scanUpToString:@"<style" intoString:nil];
}
答案 0 :(得分:1)
NSMutableArray *substrings = [[NSMutableArray alloc]init];
NSScanner *scanners = [NSScanner scannerWithString:aString];
[scanners scanUpToString:@"<style type=" intoString:nil]; // Scan all characters before <ol>
while(![scanners isAtEnd])
{
NSString *substring = nil;
[scanners scanString:@"<style type=" intoString:nil]; // Scan the <ol> character
if([scanners scanUpToString:@"</style>" intoString:&substring])
{
// If the space immediately followed the <ol>, this will be skipped
[substrings addObject:substring];
}
[scanners scanUpToString:@"<style type=" intoString:nil]; // Scan all characters before next <ol>
}
NSLog(@"%@",substrings);
NSString *stylesheets=[substrings objectAtIndex:0];
NSString *myStrings = @"<style type=";
NSString *tests = [myStrings stringByAppendingString:stylesheets];
NSLog(@"%@",tests);
NSString *finalstyle=[tests stringByAppendingString:@"</style>"];
NSLog(@"%@",finalstyle);