【问题标题】:How do I count the number of characters in a long string in TCL?如何计算 TCL 中长字符串中的字符数?
【发布时间】:2022-12-06 18:14:05
【问题描述】:

我试过了,但它不计算空格。 我需要将输入文本限制为 255 个字符。

put text_length [string length $additional_information]

我想计算输入的字符数,包括空格和回车,并将字符数保存在 text_length 中(带空格和回车)。

把 text_length [字符串长度 $additional_information]

【问题讨论】:

    标签: string tcl space


    【解决方案1】:

    尝试这个。

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

    它最多返回 255。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-05
      • 2021-10-25
      • 2020-03-12
      • 2022-12-21
      • 1970-01-01
      • 1970-01-01
      • 2018-04-20
      相关资源
      最近更新 更多