She*_*lam 7 regex iphone cocoa-touch objective-c nsstring
我们假设我有字符串:
"I love visiting http://www.google.com"
Run Code Online (Sandbox Code Playgroud)
如何检测令牌,http://www.google.com?
Jos*_*erg 26
你可以使用NSDataDetectors这些是在iOS4中添加的,非常有用.你想用它来创建一个数据检测器NSTextCheckingTypeLink并让它做它的事情.
NSString *testString = @"Hello http://google.com world";
NSDataDetector *detect = [[NSDataDetector alloc] initWithTypes:NSTextCheckingTypeLink error:nil];
NSArray *matches = [detect matchesInString:testString options:0 range:NSMakeRange(0, [testString length])];
NSLog(@"%@", matches);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6005 次 |
| 最近记录: |