- NSString *cleanString = [dirtyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
还有就是去除多于的空格,如下:
- 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:@" "];
NSString去除两边空格字符,like trim()[转],布布扣,bubuko.com
NSString去除两边空格字符,like trim()[转]
原文:http://www.cnblogs.com/zhkza99c/p/3794647.html