How do I count the number of characters in a long string in TCL?

I tried this, but it doesn't count the spaces. I need to limit the input text to 255 characters.

put text_length [string length $additional_information]

I would like to count the number of entered characters including spaces and enter, and save the number of characters in text_length (with space and enter).

put text_length [string length $additional_information]

3

1 Answer

Try this.

set additional_information " abc\n" set text_length [string length $additional_information] puts $text_length if {$text_length > 255} { .button configure -state disabled } else { .button configure -state enabled } 

This should output 7 and grey out the button.

4

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like