Template:Str ≠ len

维基百科,自由的百科全书


文档图示 模板文档[查看] [编辑] [历史] [清除缓存]

{{str ≠ len}}為元模板,協助其他模板判斷所輸入的字串是否相等。

注意!在大多數使用案例中,使用本模板會比使用{{str ≥ len}}來得好(請參考下面的參見章節)。

用法[编辑]

本模板共有3至4個未命名的參數。

下面示範如何檢查「abcde」字串確實為5個字:

{{str ≠ len | abcde | 5
| 不相等。
| 相等。
}}

將會回傳:

相等。

本模板比較麻煩的是處理包含=等號的字串,此狀況可以藉由數字參數來解決。以下舉例如何檢查「ab=cde」字串是否為100個字:

{{str ≠ len 
| 1 = ab=cde 
| 2 = 100
| 3 = 不相等,"!="。
| 4 = 相等,"="。
}}

將會回傳:

不相等,"!="。

比較好的習慣是採用數字化參數,因為您永遠不知道使用者輸入的資料,是否確實丟入這個元模板當中。

參數[编辑]

詳細的參數解釋:

{{str ≠ len 
| 1 = 字串
| 2 = 長度
| 3 = 當1不等於2時回傳/產生此資料
| 4 = 當1等於2時回傳/產生此資料
}}

空字串或未定義的字串,長度將視同為0。

長度值小於0時,將視同為0。

技術細節[编辑]

本模板與{{str != len}}或{{str == len}}等效使用,但由於在MediaWiki運作不良,我們不會使用這些模板。

Even though this is a string handling template it uses efficient code. (While some of the other string handling templates are probably so heavy on the servers that we perhaps should not use them.)

Templates have problems to handle parameter data that contains pipes "|", unless the pipe is inside another template {{name|param1}} or inside a piped link [[Help:Template|help]]. Thus templates can not handle wikitables as input unless you escape them by using the {{!}} template. This makes it hard to use wikitables as parameters to templates. Instead the usual solution is to use "HTML wikimarkup" for the table code, which is more robust.

參見[编辑]