写一个字符串扩展 #import "NSString+Additions.h"
//去掉首尾的空格 判断字符串是否为空
+(BOOL) isEmpty {
return nil == self
|| 0 == [[self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length];
}
//去掉字符串首尾的空格
-(NSString *)trim{
return [self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
//移除字符串中所有空格
- (NSString*)removeAllSpace
{
NSString* result = [self stringByReplacingOccurrencesOfString:@" " withString:@""];
result = [result stringByReplacingOccurrencesOfString:@" " withString:@""];
return result;
}
时间: 2024-11-06 20:58:05