Check if an NSString is just made out of spaces

前端 未结 10 2220
夕颜
夕颜 2020-12-14 05:35

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?

10条回答
  •  自闭症患者
    2020-12-14 06:09

    Try stripping it of spaces and comparing it to @"":

    NSString *probablyEmpty = [myString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    BOOL wereOnlySpaces = [probablyEmpty isEqualToString:@""];
    

提交回复
热议问题