Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# checking white space in a textbox

Tags:

c#

How can I check in C# that is there a white space only in a textbox and perform some operation after that?

like image 504
maztt Avatar asked Nov 27 '22 03:11

maztt


1 Answers

This ensures multiple spaces are caught in your check.

 bool hasAllWhitespace = txtBox1.Text.Length>0 &&
                         txtBox1.Text.Trim().Length==0;

To check for a single space only:

 bool hasSingleWhitespace = txtBox1.Text == " ";
like image 110
p.campbell Avatar answered Dec 14 '22 21:12

p.campbell