检查是否字符串包含多个空格 [英] check does string contain more than one white space

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

问题描述

string mystring = "bbbccc  ";



如何检查,如果我的字符串包含一个以上的连续空格?

How to check if my string contains more than one consecutive whitespace?

推荐答案

我假设你正在寻找多个连续的空格。结果
我会使用 System.Text.RegularExpressions .Regex ​​

I assume you're looking for multiple consecutive whitespaces.
I'd use System.Text.RegularExpressions.Regex for that.

Regex regex = new Regex(@"\s{2,}"); // matches at least 2 whitespaces
if (regex.IsMatch(inputString))
    // do something

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

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