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

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -