Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IOS: verify if a string is an empty string

Tags:

ios

nsstring

is there a method to verify if a NSString haven't characters? example of string without characters can be:

@"" or @" " or @"\n " or @"\n\n ", I want cosider these strings as empty strings and print a nslog that say me that these are emty, what kind of control I should use?

like image 569
cyclingIsBetter Avatar asked Jun 12 '12 23:06

cyclingIsBetter


People also ask

How do you check if a string is an empty string?

The isEmpty() method checks whether a string is empty or not. This method returns true if the string is empty (length() is 0), and false if not.

How do you check if a value is an empty string?

Use the length property to check if a string is empty, e.g. if (str. length === 0) {} . If the string's length is equal to 0 , then it's empty, otherwise it isn't empty.

Does Isnull check for empty string?

In C#, IsNullOrEmpty() is a string method. It is used to check whether the specified string is null or an Empty string.

Does isEmpty check for empty string?

isEmpty(< string >)​Checks if the <string> value is an empty string containing no characters or whitespace. Returns true if the string is null or empty.


1 Answers

You can use this test:

if ([[myString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] == 0) {
    // The string is empty
}
like image 116
Sergey Kalinichenko Avatar answered Sep 18 '22 16:09

Sergey Kalinichenko