检查字符串之间是否有空格(或任何地方) [英] Check if string has space in between (or anywhere)

查看:61
本文介绍了检查字符串之间是否有空格(或任何地方)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以确定字符串中是否包含空格?

Is there a way to determine if a string has a space(s) in it?

sossjjs sskkk 应该返回 true ,而 sskskjsk 应该返回false.

sossjjs sskkk should return true, and sskskjsk should return false.

"sssss" .Trim().Length 似乎不起作用.

推荐答案

如果的目标是查看字符串是否包含实际的 space 字符(如标题中所述),而不是任何其他种类的空格字符,都可以使用:

If indeed the goal is to see if a string contains the actual space character (as described in the title), as opposed to any other sort of whitespace characters, you can use:

string s = "Hello There";
bool fHasSpace = s.Contains(" ");

如果您正在寻找检测空白的方法,则下面有几个不错的选择.

If you're looking for ways to detect whitespace, there's several great options below.

这篇关于检查字符串之间是否有空格(或任何地方)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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