Determine number of characters entered into textbox with C#
41,043
Solution 1
How about
int jj = textBox1.Text.Length;
Or am I missing something?
Solution 2
The text of the text box will be a string, so it has a Length
property, i.e.:
textBox1.Text.Length
Solution 3
TextBoxobject.Text.Length
will give you the length of textbox value.
Author by
John_Dong
Updated on July 09, 2022Comments
-
John_Dong almost 2 years
Hi I was wanting to display the number of characters entered into a textbox and I want it to update as I type how can I go about this?
Here is what I have:
int kk = textBox1.MaxLength; int jj = //This is what I need to know. string lol = jj.ToString() + "/" + kk.ToString(); label2.Text = lol;
-
Stuart Golodetz about 12 yearsI'd have thought. Jon Skeet seems to think so too, and he's a man who knows stuff! (so if I'm wrong, I'm in good company :))
-
Stuart Golodetz about 12 yearsIf you want a reference: msdn.microsoft.com/en-us/library/system.string.length.aspx
-
Jon Skeet about 12 years@John_Dong: Well it's a matter of thinking one step removed - you want to know the number of characters in the text of the text box, so you need to know a) how to get the number of characters in a string, and b) the value of a textbox as a string.
-
John_Dong about 12 yearsDo you by any chance also know how to read bytes from a file from a min and max hex offset and convert it to a string?
-
John_Dong about 12 yearsThat's what I did but I set the test on load to "0/1020" and then it changes the min value every time the text gets changed.
-
Jon Skeet about 12 years@John_Dong: Open a stream (e.g. File.Open). Seek using the Position property. Read the data you want, looping round and using the result of Stream.Read each time. Use
Encoding
to convert the bytes into text.