Check if an NSString is just made out of spaces
I want to check if a particular string is just made up of spaces. It could be any number of spaces, including zero. What is the best way to determine that? Alexsander Akers NSString *str = @" "; NSCharacterSet *set = [NSCharacterSet whitespaceCharacterSet]; if ([[str stringByTrimmingCharactersInSet: set] length] == 0) { // String contains only whitespace. } Try stripping it of spaces and comparing it to @"": NSString *probablyEmpty = [myString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; BOOL wereOnlySpaces = [probablyEmpty isEqualToString:@""]; It's significantly