去掉获得通讯录号码中的空格 NO-BREAK SPACE

1. To trim white space in front and end.

NSString *pickerString = @"    10 mins   ";

    pickerString = [pickerString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    NSLog(@"pickerString after : %@",pickerString);

 
2. To trim white space in between NSString.
NSString *theString = @"    Hello      this  is a   long       string!   ";

NSCharacterSet *whitespaces = [NSCharacterSet whitespaceCharacterSet];
NSPredicate *noEmptyStrings = [NSPredicate predicateWithFormat:@"SELF != ''"];

NSArray *parts = [theString componentsSeparatedByCharactersInSet:whitespaces];
NSArray *filteredArray = [parts filteredArrayUsingPredicate:noEmptyStrings];
theString = [filteredArray componentsJoinedByString:@" "];
posted @ 2014-10-17 15:33  夜深人未静  阅读(382)  评论(0编辑  收藏  举报