zoukankan      html  css  js  c++  java
  • 【IOS】判断字符串为空和只为空格解决办法

     1 + (BOOL)isBlankString:(NSString *)string   
     2 {
     3     if (string == nil) 
     4     {
     5         returnYES;
     6     }
     7     if (string == NULL) 
     8     {
     9         returnYES;
    10     }
    11     if ([string isKindOfClass:[NSNullclass]]) 
    12     {
    13         returnYES;
    14     }
    15     if ([[string stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet]] length]==0) 
    16     {
    17         returnYES;
    18     }
    19     returnNO;
    20 }
    21 
    22 
    23 
    24 +(Boolean) isEmptyOrNull:(NSString *) str 
    25 {
    26 
    27     if (!str) 
    28     {
    29 
    30         // null object
    31 
    32         return YES;
    33 
    34     } 
    35     else 
    36     {
    37 
    38         NSString *trimedString = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    39 
    40         if ([trimedString length] == 0) 
    41         {
    42 
    43             // empty string
    44 
    45             return YES;
    46 
    47         } 
    48         else 
    49         {
    50 
    51             // is neither empty nor null 
    52 
    53             return NO;
    54 
    55         }
    56 
    57     }
    58 }
  • 相关阅读:
    Alpha冲刺第一天
    团队项目-需求分析
    设计模式第二次作业
    设计模式第一次作业
    冲刺合集
    冲刺NO.12
    项目测试
    冲刺NO.11
    冲刺NO.9
    冲刺NO.10
  • 原文地址:https://www.cnblogs.com/DannyApple/p/3954962.html
Copyright © 2011-2022 走看看