IOS 開發(fā)中判斷NSString是否為空字符
//當(dāng) 請求網(wǎng)絡(luò) 或者獲取其他返回?cái)?shù)據(jù) 首先 要做一次判斷 數(shù)據(jù)是否為空
防止程序崩潰
程序崩潰 好比拿刀扎在程序員的心啊~
if(為空) { 做提示對話框等操作 } else { 正常執(zhí)行 }
- (BOOL) isBlankString:(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; } return NO; }
posted on 2014-02-12 17:10 ACM_Someone like you 閱讀(1387) 評論(0) 收藏 舉報(bào)
浙公網(wǎng)安備 33010602011771號(hào)