c# - Limiting words in a text box -


i'm trying create text box in c# contain 100 words , after 100th word no other text can input box.

a simple approach might inaccurate because replaces consecutive white-spaces one:

private void textbox1_textchanged(object sender, eventargs e) {     string[] words = textbox1.text.split();     int wordcount = words.length;     if (wordcount > 100)         textbox1.text = string.join(" ", words.take(100)); } 

instead of string.join replace old text:

private string oldtext; private void textbox1_textchanged(object sender, eventargs e) {     string[] words = textbox1.text.split();     int wordcount = words.length;     if (wordcount > 100)         textbox1.text = oldtext;     else         oldtext = textbox1.text; } 

Comments

Popular posts from this blog

matlab - How to equate a structure array to structure array -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -