//把連續(xù)的空格替換成一個
NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"\\s{2,}" options:NSRegularExpressionCaseInsensitive error:&error];
NSArray *arr = [regex matchesInString:originalString options:NSMatchingReportCompletion range:NSMakeRange(0, originalString.length)];
arr = [[arr reverseObjectEnumerator] allObjects];
for (NSTextCheckingResult *str in arr) {
originalString = [originalString stringByReplacingCharactersInRange:[str range] withString:@" "];
}
//去除空格
originalString = [originalString stringByReplacingOccurrencesOfString:@" "withString:@""];
originalString = [originalString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];