Search code examples
stringtclspace

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]


Solution

  • 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.