1
我正在使用NSDataDetector解析文本並檢索數字。這裏是我的代碼:NSDataDetector電話號碼
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypePhoneNumber
error:&error];
NSArray *matches = [detector matchesInString:locationAndTitle options:0 range:NSMakeRange(0,[locationAndTitle length])];
for (NSTextCheckingResult *match in matches) {
if ([match resultType] == NSTextCheckingTypePhoneNumber) {
self.theNumber = [match phoneNumber];
}
}
的問題,這是它的某個時候返回是這樣的:
電話:9729957777 或 9729957777x3547634
我不希望出現和刪除它會更難,然後使用正則表達式代碼來檢索數字。你有關於如何檢索只有號碼的任何想法。