模組:String2/doc
此頁面為 Module:String2 的說明文件
| 警告 | 此模組文件被引用於約198,000個頁面,佔全部頁面的4%。 為了避免造成大規模的影響,所有對此模組文件的編輯應先於沙盒或測試樣例上測試。 測試後無誤的版本可以一次性地加入此模組文件中,但是修改前請務必於討論頁發起討論。 模板引用數量會自動更新。 |
| File:OOjs UI icon bold-a.svg | 此模組文件已評為alpha版,可接受第三方輸入,並可用於少量頁面以檢查是否存在問題,但需要受到檢查。歡迎提供新功能或修改其輸入輸出機制的建議。 |
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}} }} | module:wikidataib第761行lua錯誤:attempt to index field 'wikibase' (a nil value) |
| {{#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