p.c*_*ell 15
这样可以确保您的支票中包含多个空格.
bool hasAllWhitespace = txtBox1.Text.Length>0 &&
txtBox1.Text.Trim().Length==0;
Run Code Online (Sandbox Code Playgroud)
仅检查单个空格:
bool hasSingleWhitespace = txtBox1.Text == " ";
Run Code Online (Sandbox Code Playgroud)
使用查看Text文本框的属性string.IsNullOrWhiteSpace.
if (string.IsNullOrWhiteSpace(myTextBox.Text) && myTextBox.Text.Length > 0)
{
// do stuff
}
Run Code Online (Sandbox Code Playgroud)
因为IsNullOrWiteSpace如果文本框为空(或属性为null)将返回true,加上Length检查确保没有在文本框中的东西.如果文本框中只有空格,则测试的组合可确保为true.
| 归档时间: |
|
| 查看次数: |
34384 次 |
| 最近记录: |