- (BOOL)isNullString:(NSString *)string {
if (string == nil || string == NULL) {
return YES;
}
if ([string isKindOfClass:[NSNull class]]) {
return YES;
}
//空格
if ([[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
return YES;
}
if ([string isKindOfClass:[NSString class]]) {
if (string.length == 0) {
return YES;
}
}
//tap键
if ([string stringByReplacingOccurrencesOfString:@"\r" withString:@""].length == 0) {
return YES;
}
//换行符
if ([string stringByReplacingOccurrencesOfString:@"\n" withString:@""].length == 0) {
return YES;
}
if ([self delSpaceAndNewline:string].length == 0) {
return YES;
}
return NO;
}
//去除所有空格和换行
- (NSString *)delSpaceAndNewline:(NSString *)string {
NSMutableString *mutStr = [NSMutableString stringWithString:string];
NSRange range = {0,mutStr.length};
[mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
NSRange range2 = {0,mutStr.length};
[mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
return mutStr;
}