Is there an equivalent in Tcl of 'string to X' functions found in C stdlib.h?

后端 未结 5 1473
南旧
南旧 2021-01-19 17:50

There are standard functions such as atof and atoi in C\'s stdlib.h for converting strings to floats / integers (and to do the reverse

5条回答
  •  渐次进展
    2021-01-19 18:28

    As noted, everything is a string in Tcl, so you can just use a given string as an integer or whatever else you need it as. The only caveat being that it needs to be something that can be interpreted as what you want to use it as (ie, you can use "a" as an integer)

    You can test to see if something can be interpreted as the type you want using the string is subcommand:

    string is integer "5" ;# true
    string is integer "a" ;# false
    string is list "a b cc" ;# true
    string is list "{a b}c" ;# false
    

提交回复
热议问题