码迷,mamicode.com
首页 > 移动开发 > 详细

【IOS】判断字符串为空和只为空格解决办法

时间:2014-09-04 00:00:07      阅读:344      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   ar   div   sp   log   

 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 }

 

【IOS】判断字符串为空和只为空格解决办法

标签:style   blog   color   os   io   ar   div   sp   log   

原文地址:http://www.cnblogs.com/DannyApple/p/3954962.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!