在文本框中检测空白 [英] Detecting whitespace in textbox

查看:24
本文介绍了在文本框中检测空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在具有多个空格(例如1 1 A)的WinForms文本框中,其中的1s之间有空格,我如何通过字符串方法或regex检测到这一点?

In a WinForms textbox with multiple whitespaces (e.g. 1 1 A), where, between the 1s, there is whitespace, how could I detect this via the string methods or regex?

推荐答案

int NumberOfWhiteSpaceOccurances(string textFromTextBox){
 char[] textHolder = textFromTextBox.toCharArray();
 int numberOfWhiteSpaceOccurances = 0;
 for(int index= 0; index < textHolder.length; index++){
   if(textHolder[index] == ' ')numberOfWhiteSpaceOccurances++;
 }
 return numberOfWhiteSpaceOccurances;
}

这篇关于在文本框中检测空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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