简体   繁体   中英

Check White Space in textbox (C#)

How to check white space in TextBox?. I want to take username as input, but there shouldn't be any white space. How to check that by returning true false?

Try this:

bool isWhitespace = txtBox.Text.Any(char.IsWhiteSpace);

This question is already resolved here

But there shouldn't be any space.

Use Trim() string function

textbox1.Text.Trim()

How to check space in text box?

bool containspaces = str.Where(c => char.IsWhiteSpace(c)).Count() > 0;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM