'\" '\" Copyright (c) 1993 The Regents of the University of California. '\" Copyright (c) 1994-1996 Sun Microsystems, Inc. '\" '\" See the file "license.terms" for information on usage and redistribution '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES. '\" '\" RCS: @(#) $Id: string.n,v 1.2 2003/11/24 05:10:00 bbbush Exp $ '\" '\" The definitions below are for supplemental macros used in Tcl/Tk '\" manual entries. '\" '\" .AP type name in/out ?indent? '\" Start paragraph describing an argument to a library procedure. '\" type is type of argument (int, etc.), in/out is either "in", "out", '\" or "in/out" to describe whether procedure reads or modifies arg, '\" and indent is equivalent to second arg of .IP (shouldn't ever be '\" needed; use .AS below instead) '\" '\" .AS ?type? ?name? '\" Give maximum sizes of arguments for setting tab stops. Type and '\" name are examples of largest possible arguments that will be passed '\" to .AP later. If args are omitted, default tab stops are used. '\" '\" .BS '\" Start box enclosure. From here until next .BE, everything will be '\" enclosed in one large box. '\" '\" .BE '\" End of box enclosure. '\" '\" .CS '\" Begin code excerpt. '\" '\" .CE '\" End code excerpt. '\" '\" .VS ?version? ?br? '\" Begin vertical sidebar, for use in marking newly-changed parts '\" of man pages. The first argument is ignored and used for recording '\" the version when the .VS was added, so that the sidebars can be '\" found and removed when they reach a certain age. If another argument '\" is present, then a line break is forced before starting the sidebar. '\" '\" .VE '\" End of vertical sidebar. '\" '\" .DS '\" Begin an indented unfilled display. '\" '\" .DE '\" End of indented unfilled display. '\" '\" .SO '\" Start of list of standard options for a Tk widget. The '\" options follow on successive lines, in four columns separated '\" by tabs. '\" '\" .SE '\" End of list of standard options for a Tk widget. '\" '\" .OP cmdName dbName dbClass '\" Start of description of a specific option. cmdName gives the '\" option's name as specified in the class command, dbName gives '\" the option's name in the option database, and dbClass gives '\" the option's class in the option database. '\" '\" .UL arg1 arg2 '\" Print arg1 underlined, then print arg2 normally. '\" '\" RCS: @(#) $Id: string.n,v 1.2 2003/11/24 05:10:00 bbbush Exp $ '\" '\" # Set up traps and other miscellaneous stuff for Tcl/Tk man pages. .if t .wh -1.3i ^B .nr ^l \n(.l .ad b '\" # Start an argument description .de AP .ie !"\\$4"" .TP \\$4 .el \{\ . ie !"\\$2"" .TP \\n()Cu . el .TP 15 .\} .ta \\n()Au \\n()Bu .ie !"\\$3"" \{\ \&\\$1 \\fI\\$2\\fP (\\$3) .\".b .\} .el \{\ .br .ie !"\\$2"" \{\ \&\\$1 \\fI\\$2\\fP .\} .el \{\ \&\\fI\\$1\\fP .\} .\} .. '\" # define tabbing values for .AP .de AS .nr )A 10n .if !"\\$1"" .nr )A \\w'\\$1'u+3n .nr )B \\n()Au+15n .\" .if !"\\$2"" .nr )B \\w'\\$2'u+\\n()Au+3n .nr )C \\n()Bu+\\w'(in/out)'u+2n .. .AS Tcl_Interp Tcl_CreateInterp in/out '\" # BS - start boxed text '\" # ^y = starting y location '\" # ^b = 1 .de BS .br .mk ^y .nr ^b 1u .if n .nf .if n .ti 0 .if n \l'\\n(.lu\(ul' .if n .fi .. '\" # BE - end boxed text (draw box now) .de BE .nf .ti 0 .mk ^t .ie n \l'\\n(^lu\(ul' .el \{\ .\" Draw four-sided box normally, but don't draw top of .\" box if the box started on an earlier page. .ie !\\n(^b-1 \{\ \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' .\} .el \}\ \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\l'|0u-1.5n\(ul' .\} .\} .fi .br .nr ^b 0 .. '\" # VS - start vertical sidebar '\" # ^Y = starting y location '\" # ^v = 1 (for troff; for nroff this doesn't matter) .de VS .if !"\\$2"" .br .mk ^Y .ie n 'mc \s12\(br\s0 .el .nr ^v 1u .. '\" # VE - end of vertical sidebar .de VE .ie n 'mc .el \{\ .ev 2 .nf .ti 0 .mk ^t \h'|\\n(^lu+3n'\L'|\\n(^Yu-1v\(bv'\v'\\n(^tu+1v-\\n(^Yu'\h'-|\\n(^lu+3n' .sp -1 .fi .ev .\} .nr ^v 0 .. '\" # Special macro to handle page bottom: finish off current '\" # box/sidebar if in box/sidebar mode, then invoked standard '\" # page bottom macro. .de ^B .ev 2 'ti 0 'nf .mk ^t .if \\n(^b \{\ .\" Draw three-sided box if this is the box's first page, .\" draw two sides but no top otherwise. .ie !\\n(^b-1 \h'-1.5n'\L'|\\n(^yu-1v'\l'\\n(^lu+3n\(ul'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c .el \h'-1.5n'\L'|\\n(^yu-1v'\h'\\n(^lu+3n'\L'\\n(^tu+1v-\\n(^yu'\h'|0u'\c .\} .if \\n(^v \{\ .nr ^x \\n(^tu+1v-\\n(^Yu \kx\h'-\\nxu'\h'|\\n(^lu+3n'\ky\L'-\\n(^xu'\v'\\n(^xu'\h'|0u'\c .\} .bp 'fi .ev .if \\n(^b \{\ .mk ^y .nr ^b 2 .\} .if \\n(^v \{\ .mk ^Y .\} .. '\" # DS - begin display .de DS .RS .nf .sp .. '\" # DE - end display .de DE .fi .RE .sp .. '\" # SO - start of list of standard options .de SO .SH "STANDARD OPTIONS" .LP .nf .ta 5.5c 11c .ft B .. '\" # SE - end of list of standard options .de SE .fi .ft R .LP See the \\fBoptions\\fR manual entry for details on the standard options. .. '\" # OP - start of full description for a single option .de OP .LP .nf .ta 4c Command-Line Name: \\fB\\$1\\fR Database Name: \\fB\\$2\\fR Database Class: \\fB\\$3\\fR .fi .IP .. '\" # CS - begin code excerpt .de CS .RS .nf .ta .25i .5i .75i 1i .. '\" # CE - end code excerpt .de CE .fi .RE .. .de UL \\$1\l'|0\(ul'\\$2 .. .TH string 3tcl 8.1 Tcl "Tcl Built-In Commands" .BS '\" Note: do not modify the .SH NAME line immediately below! .SH NAME string \- 操縱字符串 .SH "總覽 SYNOPSIS" \fBstring \fIoption arg \fR?\fIarg ...?\fR .BE .SH "描述 DESCRIPTION" .PP 依賴於 \fIoption\fR (選項)進行某種字符串操作。合法的 \fIoption\fR (可以是縮寫)有: .VS 8.1 .TP \fBstring bytelength \fIstring\fR 返回一個十進制字符串,給出在內存中表示 \fIstring\fR 用的字節數。因爲 UTF-8 使用一到三字節來表示 Unicode 字符,字節長度可能與通常的字符長度不同。一個腳本關心字節長度的情況較少見。多數情況下,你應該使用 \fBstring length\fR 操作。關於 UTF-8 表示的詳情請參考 \fBTcl_NumUtfChars\fR 手冊頁。 .TP \fBstring compare\fR ?\fB\-nocase\fR? ?\fB\-length int\fR? \fIstring1 string2\fR .VE 8.1 對字符串 \fIstring1\fR 和 \fIstring2\fR\fI \fR進行逐個字符的比較。依賴於 \fIstring1\fR 在詞典順序上(lexicographically)小於、等於、大於 \fIstring2\fR,返回 -1、0、或 1。 .VS 8.1 如果指定了 \fB-length\fR ,則在比較中只使用前 \fIlength\fR 個字符。如果 \fB-length\fR 是負數,則被忽略。如果指定了 \fB-nocase\fR ,則使用大小寫不敏感方式比較字符串。 .TP \fBstring equal\fR ?\fB\-nocase\fR? ?\fB-length int\fR? \fIstring1 string2\fR 對字符串 \fIstring1\fR 和 \fIstring2\fR\fI \fR進行逐個字符的比較。如果 \fIstring1\fR 和 \fIstring2\fR 等同則返回 1,否則返回 0。如果指定了 \fB-length\fR ,則在比較中只使用前 \fIlength\fR 個字符。如果 \fB-length\fR 是負數,則被忽略。如果指定了 \fB-nocase\fR ,則使用大小寫不敏感方式比較字符串。 .TP \fBstring first \fIstring1 string2\fR ?\fIstartIndex\fR? .VE 8.1 在 \fIstring2\fR 中查找精確的匹配 \fIstring1 \fR中的字符的一個字符序列。如果找到,返回 \fIstring2 \fR中的第一個這樣的匹配的第一個字符的索引。如果未找到,返回 -1。 .VS 8.1 如果指定了 \fIstartIndex\fR (以可被 \fBindex\fR 方法接受的任何形式),則約束查找爲在 \fIstring2\fR 中從用索引指定的字符開始。例如, .RS .CS \fBstring first a 0a23456789abcdef 5\fR .CE 將返回 \fB10\fR, but .CS \fBstring first a 0123456789abcdef 11\fR .CE 將返回 \fB\-1\fR. .RE .VE 8.1 .TP \fBstring index \fIstring charIndex\fR 返回 \fIstring\fR 參數的第 \fIcharIndex \fR個字符。\fIcharIndex\fR 中 0 對應着字符串的第一個字符。 .VS 8.1 \fIcharIndex\fR 可以被指定如下: .RS .IP \fIinteger\fR 10 用整數索引指定字符。 .IP \fBend\fR 10 字符串的最後一個字符。 .IP \fBend\-\fIinteger\fR 10 字符串最後一個字符減去指定整數偏移量(例如, \fBend-1\fR 將參照“abcd”中的“c”)。 .PP .VE 8.1 如果 \fIcharIndex\fR 小於 0 或大於等於字符串的長度則返回一個空串。 .VS 8.1 .RE .TP \fBstring is \fIclass\fR ?\fB\-strict\fR? ?\fB\-failindex \fIvarname\fR? \fIstring\fR 如果 \fIstring\fR 是指定字符類的一個有效成員則返回 1,否則返回 0。如果指定了 \fB-strict\fR,則對一個空串返回 0,否則在任何類上對一個空串返回 1。如果指定了 \fB-failindex\fR,則若函數返回 0,把字符串中類不再有效的地方的索引存儲到叫做 \fIvarname\fR 的變量中。如果函數返回 1則不設置 \fIvarname\fR 。識別下列字符類(類的名字可以被縮寫): .RS .IP \fBalnum\fR 10 任何 Unicode 字母或數字字符。 .IP \fBalpha\fR 10 任何 Unicode 字母字符。 .IP \fBascii\fR 10 值小於 \\u0080 的任何字符(這是 7-bit ascii 的範圍)。 .IP \fBboolean\fR 10 \fBTcl_GetBoolean\fR 所允許的任何形式。 .IP \fBcontrol\fR 10 任何 Unicode 控制字符。 .IP \fBdigit\fR 10 任何 Unicode 數字字符。注意這包括在 [0-9] 範圍外的字符。 .IP \fBdouble\fR 10 雙精度數在 Tcl 中的任何有效形式,可以有可選的圍繞白空格。在值下溢/上溢的情況下,返回 0 並且 \fIvarname\fR 將包含 -1。 .IP \fBfalse\fR 10 \fBTcl_GetBoolean\fR 允許的任何形式,這裏的值是假。 .IP \fBgraph\fR 10 除了空格之外的任何 Unicode 打印字符。 .IP \fBinteger\fR 10 整數在 Tcl 中的任何有效形式,可以有可選的圍繞白空格。在值下溢/上溢的情況下,返回 0 並且 \fIvarname\fR 將包含 -1。 .IP \fBlower\fR 10 任何 Unicode 小寫字母字符。. .IP \fBprint\fR 10 包括空格在內的任何 Unicode 打印字符。 .IP \fBpunct\fR 10 任何 Unicode 標點字符。 .IP \fBspace\fR 10 任何 Unicode 空格字符。 .IP \fBtrue\fR 10 \fBTcl_GetBoolean\fR 所允許的任何形式,這裏的值是真。 .IP \fBupper\fR 10 在 Unicode 中的任何大寫字符。 .IP \fBwordchar\fR 10 任何 Unicode 單字字符。它是任何字母字符和 Unicode 連接符標點字符(例如,下劃線)。 .IP \fBxdigit\fR 10 任何十六進制數字字符 ([0\-9A\-Fa\-f]). .PP 在 \fBboolean\fR、\fBtrue\fR 和 \fBfalse\fR 的情況下,如果函數將返回 0,則 \fIvarname\fR 總是被設置爲 0,原因是一個有效 boolean 值有多種本地(表示)。 .RE .TP \fBstring last \fIstring1 string2\fR ?\fIstartIndex\fR? .VE 8.1 在 \fIstring2\fR 中查找精確的匹配在 \fIstring1 \fR中的字符的一個字符序列。如果找到,返回在 \fIstring2 \fR中最後一個這樣的匹配的第一個字符的索引。如果沒有匹配,則返回 -1。 .VS 8.1 如果指定了 \fIstartIndex\fR(以可被 \fBindex\fR 方法接受的任何形式), 則查找只針對 \fIstring2\fR 中用 \fIstartIndex\fR 指定的和此前的字符。例如, .RS .CS \fBstring last a 0a23456789abcdef 15\fR .CE 將返回 \fB10\fR, 而 .CS \fBstring last a 0a23456789abcdef 9\fR .CE 將返回 \fB1\fR. .RE .VE 8.1 .TP \fBstring length \fIstring\fR 返回一個十進制字符串,給出在 \fIstring \fR中字符的數目。注意這不是必須與用於存儲這個字符串的字節的數目相同。 .VS 8.1 .TP \fBstring map\fR ?\fB\-nocase\fR? \fIcharMap string\fR 基於在 \fIcharMap \fR中的鍵-值對替代 \fIstring\fR 中的字符。\fIcharMap\fR 是形如 \fIkey value key value\fR ... 的一個列表,同於從 \fBarray get \fR返回的那種形式。在字符串中這些鍵的每個實例將被替代爲相應的值。如果指定了 \fB-nocase\fR,則進行匹配時不區別大小寫。\fIkey\fR 和 \fIvalue\fR 二者都可以是多字節的。以一種有次序的方式進行替代,所以在列表中出現在最前面的鍵將被首先檢查,以此類推。\fIstring\fR 只被重複操作(iterate)一次,所以早先的鍵替代將不影響以後的鍵匹配。例如, .RS .CS \fBstring map {abc 1 ab 2 a 3 1 0} 1abcaababcabababc\fR .CE 將返回字符串 \fB01321221\fR. .RE .TP \fBstring match\fR ?\fB\-nocase\fR? \fIpattern\fR \fIstring\fR .VE 8.1 查看 \fIpattern\fR 是否匹配 \fIstring\fR;如果是則返回 1,不是則返回 0。 .VS 8.1 如果指定了 \fB-nocase\fR,則針對字符串的模式匹配採用大小寫不敏感的方式。 .VE 8.1 對於要進行匹配的這兩個字符串,除了在 \fIpattern \fR中可以出現的下列特殊序列之外它們的內容必須相同: .RS .IP \fB*\fR 10 匹配 \fIstring \fR中任何字符的一個序列,包括一個空字符。 .IP \fB?\fR 10 匹配 \fIstring\fR 中的一個單一字符。 .IP \fB[\fIchars\fB]\fR 10 匹配在用 \fIchars \fR給出的集合中的任何字符。如果在 \fIchars\fR 中出現一個形式是 \fIx\fB\-\fIy\fR 的一個序列,則匹配在 \fIx\fR 和 \fIy\fR,之間的任何字符,包括二者。 .VS 8.1 當與 \fB\-nocase \fR一起使用的時候,範圍的端點首先被轉換爲小寫。所以在大小寫敏感匹配時 {[A\-z]} 匹配‘_’(‘_’位於‘Z’和‘a’之間),加上 \fB-nocase\fR 則將被象 {[A\-Za\-z]} 那樣對待(並可能是前者的真實意圖)。 .VE 8.1 .IP \fB\e\fIx\fR 10 匹配單一字符 \fIx\fR。這提供了一種方式避免在 \fIpattern \fR中對字符 \fB*?[]\e\fR 做特殊解釋。 .RE .TP \fBstring range \fIstring first last\fR 從 \fIstring \fR返回一個範圍的連續字符,從索引是 \fIfirst\fR 的字符開始並結束於索引是 \fIlast\fR 的字符。 索引 0 參照字符串的 .VS 8.1 第一個字符。可以按 \fBindex\fR 方法的方式指定 \fIfirst\fR 和 \fIlast\fR 。 .VE 8.1 如果 \fIfirst\fR 小於零,則把它作爲零對待,而如果 \fIlast\fR 大於等於字符串的長度,則把它作爲 \fBend\fR 對待。如果 \fIfirst\fR 大於 \fIlast\fR 則返回空串。 .VS 8.1 .TP \fBstring repeat \fIstring count\fR 把 \fIstring \fR重複 \fIcount\fR 次後返回。 .TP \fBstring replace \fIstring first last\fR ?\fInewstring\fR? 從 \fIstring\fR 刪除一個範圍的連續字符,範圍從索引是 \fIfirst\fR 的字符開始並結束於索引是 \fIlast\fR 的字符。索引 0 參照字符串的第一個字符。可以按 \fBindex\fR 方法的方式指定 \fIfirst\fR 和 \fIlast\fR 。如果指定了 \fInewstring\fR ,則把它放置在刪除的字符範圍中。如果 \fIfirst\fR 小於零,則把它作爲零對待,而如果 \fIlast\fR 大於等於字符串的長度,則把它作爲 \fBend\fR 對待。如果 \fIfirst\fR 大於 \fIlast \fR或最初的字符串的長度 ,或者 \fIlast\fR 小於 0,則不做變動的返回最初的字符串。 .TP \fBstring tolower \fIstring\fR ?\fIfirst\fR? ?\fIlast\fR? 返回一個等同於 \fIstring\fR 的值,但所有大寫(或標題)字母都被轉換爲小寫。如果指定了 \fIfirst\fR,則它參照字符串中開始修改的第一個字符的索引。如果指定了 \fIlast\fR,則它參照字符串中修改停止到(包括它)的那個字符的索引。按 \fBindex\fR 方法的方式指定 \fIfirst\fR 和 \fIlast\fR。 .TP \fBstring totitle \fIstring\fR ?\fIfirst\fR? ?\fIlast\fR? 返回等同於 \fIstring\fR 的一個值,但把 \fIstring\fR 的第一個字符轉換成它的 Unicode 標題大寫變體(如果沒有標題大寫變體則爲大寫)而把字符串的其餘部分轉換成小寫。如果指定了 \fIfirst\fR,則它參照字符串中開始修改的第一個字符的索引。如果指定了 \fIlast\fR,則它參照字符串中修改停止到(包括它)的那個字符的索引。按 \fBindex\fR 方法的方式指定 \fIfirst\fR 和 \fIlast\fR。 .TP \fBstring toupper \fIstring\fR ?\fIfirst\fR? ?\fIlast\fR? 返回一個等同於 \fIstring\fR 的值,但所有小寫(或標題)字母都被轉換爲大寫。如果指定了 \fIfirst\fR,則它參照字符串中開始修改的第一個字符的索引。如果指定了 \fIlast\fR,則它參照字符串中修改停止到(包括它)的那個字符的索引。按 \fBindex\fR 方法的方式指定 \fIfirst\fR 和 \fIlast\fR。 .VE 8.1 .TP \fBstring trim \fIstring\fR ?\fIchars\fR? 返回一個等同於 \fIstring\fR 的值,但刪除了任何前導或尾隨的用 \fIchars\fR 給出的字符集合中字符。如果未指定 \fIchars\fR 則刪除白空格(空格、tab、換行、回車)。 .TP \fBstring trimleft \fIstring\fR ?\fIchars\fR? 返回一個等同於 \fIstring\fR 的值,但刪除了任何前導的用 \fIchars\fR 給出的字符集合中字符。如果未指定 \fIchars\fR 則刪除白空格(空格、tab、換行、回車)。 .TP \fBstring trimright \fIstring\fR ?\fIchars\fR? 返回一個等同於 \fIstring\fR 的值,但刪除了任何尾隨的用 \fIchars\fR 給出的字符集合中字符。如果未指定 \fIchars\fR 則刪除白空格(空格、tab、換行、回車)。 .VS 8.1 .TP \fBstring wordend \fIstring charIndex\fR 返回包含 \fIstring \fR的第 \fIcharIndex\fR 個字符的那個字最後的字符後面的那個字符的索引。按 \fBindex\fR 方法的方式指定 \fIcharIndex\fR 。一個字被認爲是任何連續範圍的 alphanumeric (Unicode 字母或十進制數字)或下劃線(Unicode 連接符標點)字符,或除了這些之外的任何單一字符。 .TP \fBstring wordstart \fIstring charIndex\fR 返回包含 \fIstring \fR的第 \fIcharIndex\fR 個字符的那個字的第一個字符的索引。按 \fBindex\fR 方法的方式指定 \fIcharIndex\fR 。一個字被認爲是任何連續範圍的 alphanumeric (Unicode 字母或十進制數字)或下劃線(Unicode 連接符標點)字符,或除了這些之外的任何單一字符。 .VE 8.1 .SH "參見 SEE ALSO" expr(n), list(n) .SH "關鍵字 KEYWORDS" case conversion, compare, index, match, pattern, string, word, equal, ctype .SH "[中文版維護人]" .B 寒蟬退士 .SH "[中文版最新更新]" .B 2001/11/15 .SH "《中國 Linux 論壇 man 手冊頁翻譯計劃》:" .BI http://cmpp.linuxforum.net .SH "跋" .br 本頁面中文版由中文 man 手冊頁計劃提供。 .br 中文 man 手冊頁計劃:\fBhttps://github.com/man-pages-zh/manpages-zh\fR