检查NSString是否只是由空格 [英] Check if an NSString is just made out of spaces

查看:211
本文介绍了检查NSString是否只是由空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查一个特定的字符串是否只是由空格组成。它可以是任何数量的空间,包括零。

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?

推荐答案

NSString *str = @"         ";
NSCharacterSet *set = [NSCharacterSet whitespaceCharacterSet];
if ([[str stringByTrimmingCharactersInSet: set] length] == 0)
{
    // String contains only whitespace.
}

这篇关于检查NSString是否只是由空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆