NSString去除两边空格字符,like trim()[转]

it2022-05-05  151

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:@" "];  

转载于:https://www.cnblogs.com/zhkza99c/p/3794647.html

相关资源:各显卡算力对照表!

最新回复(0)