я пытаюсь оценить это предложение: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 ** ... –
'NSLog (@ "% @ цвета,% @,% @", redComponent, greenComponent, blueComponent);' Это должно быть 'NSLog (@" цвет% @,% @,% @ ", [redComponent stringValue], [greenComponent stringValue], [blueComponent stringValue]);' –
@AhmedZ .: Использование '% @' для 'NSNumber' не является проблемой вообще. –