Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

How do you Count the amount of letters in a Single Line TextBox?

 

Example: TextBox1.Text = 123456789

 

TextBox2.Text = 9 <<-- Amount of characters in TextBox1.Text

It's not impossible, it's Inevitable.
Posted
TextBox2.Text = TextBox1.Text.Length

 

That gives you a count of the characters, which includes spaces - not just letters.

 

You'd have to strip out the spaces to get JUST the number of letters.

Posted

True.

 

This would get rid of the spaces before counting the characters. Although, it would still count any tabs or other whitespace...

TextBox2.Text = TextBox1.Text.Trim(" ").Length

Posted
True.

 

This would get rid of the spaces before counting the characters. Although, it would still count any tabs or other whitespace...

TextBox2.Text = TextBox1.Text.Trim(" ").Length

 

Thanks, exactly what I needed. :D

It's not impossible, it's Inevitable.
Posted

So how would you get just letters?

 

could you use Regular Expressions? [A-Za-z] or something like that is all letters upper or lower case.

 

One method I've seen used as the brute force method.

 

string UpperCaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

string LowerCaseLetters = "abcdefghijklmnopqrstuvwxyz";

string Digits = "1234567890";

string AllLetters = UpperCaseLetters + LowerCaseLetters;

 

then do a search for characters that appear in your string, which are all of the letters. I'd place that code, but I don't have visual studio on me at the moment.

Posted
I believe there is a regular expression for any textual character. I seem to have lost that bit of information from my brain at the moment though.
Wanna-Be C# Superstar

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...