Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想检查一个是否NSString以 19xx 或 20xx 结尾,其中 x 是任何有效数字。
NSString
我怎样才能做到这一点?
听起来像带有正则表达式的谓词符合您的要求:
NSString *str = @"2013"; NSPredicate *yearPredicate = [NSPredicate predicateWithFormat: @"SELF MATCHES '(19|20)[0-9]{2}'"]; BOOL matched = [yearPredicate evaluateWithObject: str];