How can I check in C# that is there a white space only in a textbox and perform some operation after that?
if (String.IsNullOrWhiteSpace(txtBox.Text))
{
// so stuff
}
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 == " ";
var Rxwhitesp = new Regex(@"\s");
string textboxstring = textbox.Text;
string textboxfirststring = textbox.Text.First().ToString();
if (Rxwhitesp.IsMatch(textboxfirststring) && (textboxstring.Length == 1))
{
// write code for true condition
}
else
{
// write code for false condition
}