判断字符串

2018-08-30  本文已影响5人  冉俊
/**
 *
 *  判断空字符串
 *
 */
+(NSString*)convertNull:(id)object{
    // 转换空串
    if ([object isEqual:[NSNull null]]) {
        return @"";
    }
    else if ([object isKindOfClass:[NSNull class]])
    {
        return @"";
    }
    else if (object==nil){
        return @"";
    }
    else if ([object isKindOfClass:[NSNumber class]])
    {
        return ((NSNumber *)object).stringValue;
    }
    else if ([object isEqualToString:@"(null)"] || [object isEqualToString:@"<null>"] || [object isEqualToString:@"null"]){
        return @"";
    }
    return object;
}
/**
 *
 *  判断字符串对象是否有值
 *
 */
- (BOOL)hasValue {
    if (![self isKindOfClass:[NSString class]]) {
        return NO;
    }
    if ([self isEqualToString:@""] || [self isEqualToString:@"(null)"] || [self isEqualToString:@"<null>"]|| [self isEqualToString:@"null"]) {
        return NO;
    }
    if ([[self stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length]==0) {
        return NO;
    }
    return YES;
}
上一篇下一篇

猜你喜欢

热点阅读