basic instructions
Tcl treats all variable values as strings and stores them as strings. Subscripts list the more useful string manipulation commands:
append | Append value to end of string |
---|---|
binary | Binary string operations |
format | String formatting |
regexp | regular expression |
legal sub | String simulation matching and replacement with string patterns |
scan | String decomposition |
string options | String operations and command sets |
subst | Character substitution (replacing special strings) |
append command
The append command is relatively simple. It connects a string to the end of another string to form a new string. It should be noted that this command will directly modify the variables.
format command
The format command formats a string according to a set of format specifications. However, this operation does not change the content of the manipulated string.
The spec variable contains the format description keyword and additional text.
The following table shows the format conversion symbols:
The following table shows the format identifier:
example of the position specifier:
scan
The scan command parses a string according to the format descriptor and assigns the corresponding value to the following variable, returning the number of successful conversions.
The format descriptor of scan is almost the same as format. The function of %c is opposite to format, which is to convert an ASCII character into the corresponding integer value. format converts multiple target variables into ige strings, while scan can decompose a string into multiple variables.
The scan format includes the concept of a set, which uses brackets to define a set of characters. This set matches one or more characters of the string to the destination variable.
If no output variable is specified in the scan command, it does not return the number of successful conversions, but the result of successful conversions.
binary
According to the storage organization form of the data, it can be divided into ASCII form and binary form. When stored in ASCII, each byte stores an ASCII code, representing a numeric character. When stored in binary, for example, an integer 10000 is represented by ASCII code. Each numeric character is stored in one byte of ASCII code, requiring a total of 5 bytes of storage space. However, using binary, only two bytes are needed. , to store the corresponding binary code, saving more space.
string
String is the basic data type in TCL, so there are a lot of string manipulation commands. A more important issue is pattern matching. Pattern matching is used to match strings with specified patterns to perform string comparison, search and other operations.
string command list
String comparison