對於輸入框爲空及輸入參數只有空格的判斷ios

常常有需求 要判斷不能爲空spa

-(Bool) isEmpty:(NSString *) str {rem

    if (!str) {string

        return true;it

    } else {im

//A character set containing only the whitespace characters space (U+0020) and tab (U+0009) and the newline and nextline characters (U+000A–U+000D, U+0085).d3

        NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];next

 

//Returns a new string made by removing from both ends of the receiver characters contained in a given character set.margin

        NSString *trimedString = [str stringByTrimmingCharactersInSet:set];tab

 

        if ([trimedString length] == 0) {vi

            return true;

        } else {

            return false;

        }

    }

}

或者:

判斷輸入是否爲空格
if( [[yxCustomerVo.customerName stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length]==0)

{   

     return NO;

}

相關文章
相關標籤/搜索