模板: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.

参见