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

Time:12-07

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]

CodePudding user response:

Try this.

set additional_information "   abc\n"
set text_length [string length [string range $additional_information 0 254]]
puts $text_length
# outputs 7

It will return 255 at most.

  • Related