saving database without empty string but spaces are accepting while i used @"" in sqlite in cocoa
i am new to cocoa sqlite in m开发者_运维知识库y app i am saving database in table with student data. when i am giving same name it is not accepting the name its fine, but when i giving space rather than name it accepting the spaces rather than any string. i used @"" to check if the name is empty or not , but my problem is it taking spaces..... so i want to avoid the spaces to save my data
Looking at the NSString documentation, it appears you need to use stringByTrimmingCharactersInSet:
, to trim the whitespace from the string before saving it. Something like this should work:
// Remove whitespace
NSString *trimmedString = [enteredName stringByTrimmingCharactersInSet:whitespaceCharacterSet];
// Check if the string is empty
if(![trimmedString isEqualToString:@""])
{
// Save...
}
精彩评论