C# checking white space in a textbox

后端 未结 9 859
孤独总比滥情好
孤独总比滥情好 2021-01-03 06:45

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

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 07:27

            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
            }
    

提交回复
热议问题