编辑“︁
Template:Str mid/doc
”︁
跳转到导航
跳转到搜索
这是
Str mid
模板的
文档页面
。
警告:
您没有登录。如果您进行任何编辑,您的IP地址会公开展示。如果您
登录
或
创建账号
,您的编辑会以您的用户名署名,此外还有其他益处。
反垃圾检查。
不要
加入这个!
{{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>
摘要:
请注意,所有对Local Chinese Wikipedia的贡献均可能会被其他贡献者编辑、修改或删除。如果您不希望您的文字作品被随意编辑,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源(详情请见
Project:著作权
)。
未经许可,请勿提交受著作权保护的作品!
取消
编辑帮助
(在新窗口中打开)
导航菜单
个人工具
未登录
讨论
贡献
创建账号
登录
命名空间
模板
讨论
大陆简体
不转换
简体
繁體
大陆简体
香港繁體
澳門繁體
大马简体
新加坡简体
臺灣正體
查看
阅读
编辑
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息