模块:String2/doc
这是Module:String2的文档页面
| 此模块文档被引用于约218,000个页面,占全部页面的3%。 为了避免造成大规模的影响,所有对此模块文档的编辑应先于沙盒或测试样例上测试。实施修改前,建议先在讨论页发起讨论。 模板引用数量会自动更新。 |
| 此模块文档已评为beta版,可广泛使用。因其新近完成,请谨慎使用,以确保输出结果符合预期。 |
The module “String2” contains 4 available calls that convert strings to upper, lower, sentence or title case.
The sentence case function finds the first letter and capitalises that, so it works properly with text containing wiki-markup. Compare {{#invoke:String2|sentence|[[action game]]}} -> Action game with {{ucfirst:{{lc:[[action game]]}}}} -> action game. Piped wiki-links are handled as well: {{#invoke:String2|sentence|[[trimix (breathing gas)|trimix]]}} -> Trimix.
The title case function capitalises the first letter of each word in the text, apart from a number of short words recommended by The U.S. Government Printing Office Style Manual.
Further functions commonly used on strings would be useful additions.
用法
[编辑]{#invoke:String2 | upper |…}}
{#invoke:String2 | lower |…}}
{#invoke:String2 | sentence |…}}
{#invoke:String2 | title |…}}
参数
[编辑]Just one unnamed parameter is used, representing the text to be converted to the required case.
范例
[编辑]| Input | Output |
|---|---|
| {{#invoke:String2| upper | abcd }} | 脚本错误:函数“upper”不存在。 |
| {{#invoke:String2| upper | abCD }} | 脚本错误:函数“upper”不存在。 |
| {{#invoke:String2| upper | ABcd }} | 脚本错误:函数“upper”不存在。 |
| {{#invoke:String2| upper | ABCD }} | 脚本错误:函数“upper”不存在。 |
| {{#invoke:String2| upper | }} | 脚本错误:函数“upper”不存在。 |
| {{#invoke:String2| lower | abcd }} | 脚本错误:函数“lower”不存在。 |
| {{#invoke:String2| lower | abCD }} | 脚本错误:函数“lower”不存在。 |
| {{#invoke:String2| lower | ABcd }} | 脚本错误:函数“lower”不存在。 |
| {{#invoke:String2| lower | ABCD }} | 脚本错误:函数“lower”不存在。 |
| {{#invoke:String2| lower | }} | 脚本错误:函数“lower”不存在。 |
| {{#invoke:String2| sentence | abcd }} | Abcd |
| {{#invoke:String2| sentence | abCD }} | Abcd |
| {{#invoke:String2| sentence | ABcd }} | Abcd |
| {{#invoke:String2| sentence | ABCD }} | Abcd |
| {{#invoke:String2| sentence | [[action game]] }} | Action game |
| {{#invoke:String2| sentence | [[trimix (breathing gas)|trimix]] }} | Trimix |
| {{#invoke:String2 | sentence | {{#invoke:WikidataIB |getValue |P136 |name=genre |fetchwikidata=ALL |qid=Q1396889}} }} | 影射小说、寓言 |
| {{#invoke:String2| sentence | }} | |
| {{#invoke:String2| title | abcd }} | Abcd |
| {{#invoke:String2| title | abCD }} | Abcd |
| {{#invoke:String2| title | ABcd }} | Abcd |
| {{#invoke:String2| title | ABCD }} | Abcd |
| {{#invoke:String2| title | }} | |
| {{#invoke:String2| title | The Vitamins Are In My Fresh California Raisins}} | The Vitamins Are in My Fresh California Raisins |
参见
[编辑]Module:String for the following functions:
- len
- sub
- sublength
- match
- pos
- str_find
- find
- replace
- rep