常用方法
[NSCharacterSet alphanumericCharacterSet]; //所有数字和字母(大小写)
[NSCharacterSet decimalDigitCharacterSet]; //0-9的数字
[NSCharacterSet letterCharacterSet]; //所有字母
[NSCharacterSet lowercaseLetterCharacterSet]; //小写字母
[NSCharacterSet uppercaseLetterCharacterSet]; //大写字母
[NSCharacterSet punctuationCharacterSet]; //标点符号
[NSCharacterSet whitespaceAndNewlineCharacterSet]; //空格和换行符
[NSCharacterSet whitespaceCharacterSet]; //空格
挤压空格
NSString *string = @" Lorem ipsum dolar sit amet.";
string = [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
NSArray *components = [string componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
components = [components filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self <> ''"]];
string = [components componentsJoinedByString:@" "];
//string = "Lorem ipsum dolar sit amet."
不要用 NSCharacterSet 来分词。 用 CFStringTokenizer 来替代它。