参数及使用方法
{{replace|字串|替換原文|替換為|count=替換次數}}
将字串填入模板参数1,输出时每出现一个参数2的指定原文,就会被替换为参数3的文字,可以用count参数限制替换次数(不指定则全部替换)。前三个参数对所有空格敏感。
范例
{{replace|One two two three two four twotwo five|two|NINE}}
→ One NINE NINE three NINE four NINENINE five
{{replace|One two two three two four twotwo five|two|NINE|count=2}}
→ One NINE NINE three two four twotwo five
空格
{{replace|One-two two-three two-four twotwo-five|-|—}}
→ One—two two—three two—four twotwo—five
{{replace|One-two two-three two-four twotwo-five|- |—}}
→ One-two two-three two-four twotwo-five
参见
字符串处理模板 |
---|
|
---|
根据数量处理 | | {{str right}} | 返回从左向右移除若干个字符后的字符串 | {{str rightc}} | 返回从后向前指定数量的字符串,如果字符串为空则返回一个参数 | {{str sub old}} | To trim down to a specified number, starting at a given number from the left. | {{str sub new}} | Select a substr based on starting and ending index. | {{str index}} | 返回字符串的第×个字符 |
|
|
---|
根据条件处理 | |
---|
专用于Wiki语法 | | {{WikiProjectbasename}} | Removes "WikiProject" from a pagename. | {{remove unranked}} | Removes the string "unranked_" from the left of a string (taxonomy). | {{ship prefix}} | Returns the length of a ship's name prefix, if listed (ship names). | {{title year}} | Returns the 4-digit year from a pagename, if any. |
|
|
---|
|
|
插入、替换、长度 |
---|
{{strloc insert}} | Inserts a string at character location strloc, or appends if strloc<=0. | {{loop}} | 特定次数重复字串。 | {{replace}} | 在字串中查找并全部替换某字串后返回。 | {{str rep}} | 在字串中查找并替换首次出现的某字串后返回。 | {{digits}} | 移除字串中不是数字(0~9)的字元。 |
|
|
|
|
|
|