Tcl language Note: string command in Tcl

Source: Internet
Author: User
Tags character classes

First, Introduction

string is TCL There are a number of string manipulation commands in the base data type. A more important problem is pattern matching, which matches strings to the specified pattern (format) by pattern matching for string comparisons, searches, and so on.

Ii. List of STRING commands

Command

Description

string ByteLength Str

Returns the number of bytes used to store the string.

string compare ?-nocase??-

Length len str1 str2

Compares strings based on dictionary order. The-nocase option indicates a case-insensitive relation. The-length option indicates that only the first part of the specified length is compared. Returns if the string is the same

0 (STR1=STR2), if the order of STR1 returns 1 (STR1<STR2) than str2, other cases return 1 (STR1>STR2).

string equal ?-nocase? str1 str2

Compares a string, returns 1, otherwise returns 0.

string First str1 str2

Returns the index position of the first occurrence of str1 in str2, or 1 if not found

String Index STR Index

Returns the character at the specified position. The index number starts at 0. Returns the last character if Index is end.

string is class-strict??-failindex varname? Str

Determines the type of the string, and returns 1 if it is a specified type. Character types such as integral type,

Boolean and so on. If-strict is used, the null character is not matched, otherwise it is always matched. If Failindex is specified, the character index of the non-class string is assigned to the varname variable. The detailed character classes are described in the following sections (table 4-7).

string Last str1 str2

Returns the position index of the last occurrence of str2 in str1. No search to return-1.

string Length Str

Returns the number of characters in Str

string map ?-nocase? Charmap str

Returns a new string that results from the mapping of characters in STR to the input and output lists in Charmap. See the "String Mapping" section of this section.

string Match Pattern Str

If STR matches pattern, it returns 1, otherwise 0 is returned. It's a wildcard style match. See the "String matching" section of this section.

String Range str index1 INDEX2

Returns the string from Index1 to Index2 in Str.

String Repeat Str Count

Returns a string that repeats count times for Str.

String Replace str First last newstr?

Replaces a string from first to last ending with the NEWSTR string. If NEWSTR is not, then this part of the string content is deleted.

string ToLower str. first? Last?

Converts the character of the specified range to lowercase format.

string Totile str. first? Last?

By substituting the first character with the Unicode heading character or uppercase, and the rest of the methods replaced by lowercase, the STR is converted to the start letter capitalization form. You can specify the range of operations with parameters.

string ToUpper string ? first?? last?

Converts the character of the specified range to uppercase.

string Trim str ? chars?

Removes the characters specified in chars from both ends of Str. Chars default is a null character.

string Trimleft str ? chars?

Removes the character specified in chars from the beginning of Str. Chars default is a null character.

string TrimRight str. chars?

Removes the character specified in chars from the end of Str. Chars default is a null character.

string Wordend STR Index

Returns the index position of the character in Str after the index position of the word that contains the character.

string Wordstart STR Index

Returns the index position of the first character in a word in Str that contains the character at index position.

Description: The content between the two question marks in the command is either option, which indicates what is optional according to the actual needs. These commands for strings are more similar in use. The commonly used string operations are:

-string match: string matching (or comparison);

-Uppercase and lowercase conversions: ToLower and Totopper and Totile;

-Equal operation;

-string Compare;

-String range;

-String replace, and so on.

Tcl language Note: string command in Tcl

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.