我有一個字符串(tagName),我想知道它是否與以下任何字符串匹配。什麼是最好/最有效的方式來做到這一點?使用數組並通過它循環?或者這種醜陋的方式是最好的方式?最優雅/有效的方法來比較一個字符串與許多目標c?
if ([tagName isEqualToString:@"a"] ||
[tagName isEqualToString:@"dd"] ||
[tagName isEqualToString:@"li"] ||
[tagName isEqualToString:@"span"] ||
[tagName isEqualToString:@"br"] ||
[tagName isEqualToString:@"b"] ||
[tagName isEqualToString:@"big"] ||
[tagName isEqualToString:@"em"] ||
[tagName isEqualToString:@"i"] ||
[tagName isEqualToString:@"u"] ||
[tagName isEqualToString:@"small"] ||
[tagName isEqualToString:@"strong"] ||
[tagName isEqualToString:@"sub"] ||
[tagName isEqualToString:@"sup"] ||
[tagName isEqualToString:@"ins"] ||
[tagName isEqualToString:@"del"] ||
[tagName isEqualToString:@"code"] ||
[tagName isEqualToString:@"kbd"] ||
[tagName isEqualToString:@"samp"] ||
[tagName isEqualToString:@"tt"] ||
[tagName isEqualToString:@"var"] ||
[tagName isEqualToString:@"pre"] ||
[tagName isEqualToString:@"abbr"] ||
[tagName isEqualToString:@"center"] ||
[tagName isEqualToString:@"acronym"] ||
[tagName isEqualToString:@"address"] ||
[tagName isEqualToString:@"bdo"] ||
[tagName isEqualToString:@"blockquote"] ||
[tagName isEqualToString:@"q"] ||
[tagName isEqualToString:@"cite"] ||
[tagName isEqualToString:@"img"] ||
[tagName isEqualToString:@"p"] ||
[tagName isEqualToString:@"s"] ||
[tagName isEqualToString:@"font"] ||
[tagName isEqualToString:@"strike"] ||
[tagName isEqualToString:@"caption"] ||
[tagName isEqualToString:@"th"] ||
[tagName isEqualToString:@"tr"] ||
[tagName isEqualToString:@"td"] ||
[tagName isEqualToString:@"thead"] ||
[tagName isEqualToString:@"tbody"] ||
[tagName isEqualToString:@"tfoot"] ||
[tagName isEqualToString:@"col"] ||
[tagName isEqualToString:@"colgroup"] ||
[tagName isEqualToString:@"dfn"]
) {
啊,對不起,我誤解,你是正確的。 – rooftop 2012-02-18 22:24:01