跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
Tiancheng Wiki
搜索
搜索
中文(中国大陆)
外观
创建账号
登录
个人工具
创建账号
登录
查看“︁模板:Str mid/doc”︁的源代码
模板
讨论
大陆简体
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
常规
链入页面
相关更改
页面信息
外观
移至侧栏
隐藏
←
模板:Str mid/doc
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
{{Documentation subpage}} {{lua|Module:String}} {{High-use|all-pages=yes}} <!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE --> === Usage === Characters in the source string are counted: the first is index {{code|1=1}}, the last one is index {{code|length of string}}. The substring requested can be defined by these two indexes. Also, the substring can be defined by one index, and the substring length. The options are: <nowiki> {{str mid|<string>|<index of first character>|<length of substring>|<index of last character>}} </nowiki> It returns a part of the <string>, starting with character on position ''index'', length <sublength>, last character returned is end index. *<nowiki>{{str mid|Abcdefghijklmnopqrstuvwxyz|5|3}}</nowiki> → {{str mid|Abcdefghijklmnopqrstuvwxyz|5|3}} If parameter 2 is omitted, start is from character 1: *<nowiki>{{str mid|Abcdefghijklmnopqrstuvwxyz||5}}</nowiki> → {{str mid|Abcdefghijklmnopqrstuvwxyz||5}} If parameter 3 is omitted, the whole rest of the string is returned: *<nowiki>{{str mid|Abcdefghijklmnopqrstuvwxyz|15}}</nowiki> → {{str mid|Abcdefghijklmnopqrstuvwxyz|15}} === Counting from the end === By entering a ''negative value'', the index is counted ''from the end'': *<nowiki>{{str mid|Abcdefghijklmnopqrstuvwxyz|-7|4}}</nowiki> → {{str mid|Abcdefghijklmnopqrstuvwxyz|-7|4}} *<nowiki>{{str mid|Abcdefghijklmnopqrstuvwxyz|-7}}</nowiki> → {{str mid|Abcdefghijklmnopqrstuvwxyz|-7}} === Instead if substring length, use index for last character === By using parameter {{para|4|''n''}}, a number, you do not ask for substring length, but the last character (as counted from the start of the input string): *<nowiki>{{str mid|Abcdefghijklmnopqrstuvwxyz|5||7}}</nowiki> → {{str mid|Abcdefghijklmnopqrstuvwxyz|5||7}} ===Spaces are kept=== In the returned substring, spaces are kept: *<nowiki>>{{str mid|I like this.|2|6}}<</nowiki> → >{{str mid|I like this,|2|6}}< But the input string is trimmed: *<nowiki>>{{str mid| I like this. |2|6}}<</nowiki> → >{{str mid| I like this. |2|6}}< ===Error messages=== When the ranges (either param2 or the substring length) is out impossible in the string, an error is returned: *<nowiki>{{str mid|Abcdefghijklmnopqrstuvwxyz|30}}</nowiki> → {{str mid|Abcdefghijklmnopqrstuvwxyz|30|ignore errors=false|no category=true}} *<nowiki>{{str mid|Abcdefghijklmnopqrstuvwxyz|0|45}}</nowiki> → {{str mid|Abcdefghijklmnopqrstuvwxyz|5|45|ignore errors=false|no category=true}} The error can be suppressed by using {{para|ignore errors|true}}. A blank (empty string) will be returned: *<nowiki>{{str mid|Abcdefghijklmnopqrstuvwxyz|0|45|ignore errors=true}}</nowiki> → {{str mid|Abcdefghijklmnopqrstuvwxyz|5|45|ignore errors=true}} ====Error category==== * {{para|no category|true}} switches off category adding. * {{para|error category|<nowiki>[[Category:Your category name]]</nowiki>}} sets the category to be added when in case of an error.<br/> ::Default is [[:Category:Errors reported by Module String]]. === See also === {{string-handling templates}} <includeonly> <!-- CATEGORIES AND INTERWIKIS HERE, THANKS --> [[Category:字符串處理模板|{{PAGENAME}}]] </includeonly>
返回
模板:Str mid/doc
。
搜索
搜索
查看“︁模板:Str mid/doc”︁的源代码
添加语言
添加话题