分开我试图评价这句话:NsRegularExpressions几个浮点数用逗号
<font color="0.839216,0.839216,0.839216" strokeColor="none" size="35" face="Avenir-Book">
我需要使用此代码提取颜色属性
的3个浮点值:
NSRegularExpression* colorRegex = [[[NSRegularExpression alloc] initWithPattern:@"color=([0-9]+),([0-9]+),([0-9]+)" options:0 error:NULL] autorelease];
[colorRegex enumerateMatchesInString:tag options:0 range:NSMakeRange(0, [tag length]) usingBlock:^(NSTextCheckingResult *match, NSMatchingFlags flags, BOOL *stop){
NSNumber *redComponent=[NSNumber numberWithFloat: [[tag substringWithRange: match.range] floatValue] ];
NSNumber *greenComponent=[NSNumber numberWithFloat: [[tag substringWithRange: match.range ] floatValue] ];
NSNumber *blueComponent=[NSNumber numberWithFloat: [[tag substringWithRange: match.range] floatValue] ];
self.color=[[UIColor alloc] initWithRed:redComponent.floatValue green:greenComponent.floatValue blue:blueComponent.floatValue alpha:1];
NSLog(@"color %@,%@,%@",redComponent,greenComponent,blueComponent);
我测试了几个正则表达式,但我没有成功,有人可以帮助我吗?
您正在使用**%@ **在NSLog中为** NSNumber ** ... – 2013-05-14 09:45:17
'NSLog(@“color%@,%@,%@”,redComponent,greenComponent,blueComponent);' 这应该是 'NSLog(@“color% @,%@,%@“,[redComponent stringValue],[greenComponent stringValue],[blueComponent stringValue]);' – 2013-05-14 09:46:43
@AhmedZ .:对'NSNumber'使用'%@'完全没有问题。 – 2013-05-14 09:52:27