如何检查字符串是否包含空格
如何检查字符串字符之间是否包含空格?
How to check whether a string contains whitespaces in between characters?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何检查字符串字符之间是否包含空格?
How to check whether a string contains whitespaces in between characters?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
使用
rangeOfCharactersFromSet:
注意:这也会在字符串的开头或结尾查找空格。如果你不想先修剪字符串......
use
rangeOfCharactersFromSet:
note: this will also find whitespace at the beginning or end of the string. If you don't want this trim the string first...
您还可以按照以下步骤操作:
如果字符串中存在空格,那么它将分隔这些空格并将不同的组件存储在数组中。现在您需要计算数组的计数。如果count大于1,则意味着有两个组成部分,即存在空白。
You can also follow these steps:
If there is any whitespace in your string, then it will separate those and store different components in the array. Now you need to take the count of array. If count is greater than 1, it means there are two components, i.e, presence of white space.