PureSc0pe Posted August 4, 2004 Posted August 4, 2004 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 Quote It's not impossible, it's Inevitable.
Denaes Posted August 4, 2004 Posted August 4, 2004 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. Quote
JRichmond Posted August 4, 2004 Posted August 4, 2004 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 Quote
PureSc0pe Posted August 5, 2004 Author Posted August 5, 2004 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 Quote It's not impossible, it's Inevitable.
Denaes Posted August 5, 2004 Posted August 5, 2004 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. Quote
VBAHole22 Posted August 5, 2004 Posted August 5, 2004 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. Quote Wanna-Be C# Superstar
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.