打开/关闭菜单
打开/关闭外观设置菜单
打开/关闭个人菜单
未登录
未登录用户的IP地址会在进行任意编辑后公开展示。

模板:Str mid/doc

来自Tiancheng Wiki

{{#if:

|

{{#if:x| | }} | {{#switch:doc| {{{override}}}| doc | Doc | documentation | Documentation | 文档 | 文件 = {{#ifeq:show| show|

}}{{#if:| | [[Category:{{#switch:模板|User=用户|Wikipedia=维基百科|Template=模板}}说明文件]]}}}}

}}

{{#iferror:

|

}}

Usage

Characters in the source string are counted: the first is index <syntaxhighlight lang="text" inline="">1</syntaxhighlight>, the last one is index <syntaxhighlight lang="text" inline="">length of string</syntaxhighlight>. 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: {{str mid|<string>|<index of first character>|<length of substring>|<index of last character>}} It returns a part of the <string>, starting with character on position index, length <sublength>, last character returned is end index.

  • {{str mid|Abcdefghijklmnopqrstuvwxyz|5|3}} → {{#ifexpr:({{#if:3|3|1}}=0) or (47=0)|
|{{#if:{{#if:5|{{#if:3|{{#if:|{{#ifexpr:((-5+1)<>3) and (5*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j= do not match requested substring length {{ safesubst:#if:1|3}}}}|}}}}}}|{{#if:5|{{#if:3|{{#if:|{{#ifexpr:((-5+1)<>3) and (5*<>0)|Error using {{[[{{#switch:

|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j= do not match requested substring length {{ safesubst:#if:1|3}}}}|}}}}}}

 |Abcdefghijklmnopqrstuvwxyz}}}}{{safesubst:#switch: no
|no
|n
|false
|f
|否
|0        = 
|         = 
|¬        = 
|yes
|y
|true
|t
|是
|1        = _IN:_i2=5_sublen3=3_j4=u_min=47_CORE:slen:47_i={{#if:5}|5|{{#ifexpr:({{#if:3|1|0}} and {{#if:|1|0}})|{{#expr:47-3+{{#ifexpr:3<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:3||0|3}}<0|yes|no}}_tchk={{#if:{{#if:5|{{#if:3|{{#if:|{{#ifexpr:((-5+1)<>3) and (5*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j= do not match requested substring length {{ safesubst:#if:1|3}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:3|3|1}}=0) or (47=0)}}

|#default = _IN:_i2=5_sublen3=3_j4=u_min=47_CORE:slen:47_i={{#if:5}|5|{{#ifexpr:({{#if:3|1|0}} and {{#if:|1|0}})|{{#expr:47-3+{{#ifexpr:3<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:3||0|3}}<0|yes|no}}_tchk={{#if:{{#if:5|{{#if:3|{{#if:|{{#ifexpr:((-5+1)<>3) and (5*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j= do not match requested substring length {{ safesubst:#if:1|3}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:3|3|1}}=0) or (47=0)}} }}

If parameter 2 is omitted, start is from character 1:

  • {{str mid|Abcdefghijklmnopqrstuvwxyz||5}} → {{#ifexpr:({{#if:5|5|1}}=0) or (47=0)|
|{{#if:{{#if:|{{#if:5|{{#if:|{{#ifexpr:((-+1)<>5) and (*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i= and j= do not match requested substring length {{ safesubst:#if:1|5}}}}|}}}}}}|{{#if:|{{#if:5|{{#if:|{{#ifexpr:((-+1)<>5) and (*<>0)|Error using {{[[{{#switch:

|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i= and j= do not match requested substring length {{ safesubst:#if:1|5}}}}|}}}}}}

 |Abcdefghijklmnopqrstuvwxyz}}}}{{safesubst:#switch: no
|no
|n
|false
|f
|否
|0        = 
|         = 
|¬        = 
|yes
|y
|true
|t
|是
|1        = _IN:_i2=_sublen3=5_j4=u_min=47_CORE:slen:47_i={{#if:}||{{#ifexpr:({{#if:5|1|0}} and {{#if:|1|0}})|{{#expr:47-5+{{#ifexpr:5<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:5||0|5}}<0|yes|no}}_tchk={{#if:{{#if:|{{#if:5|{{#if:|{{#ifexpr:((-+1)<>5) and (*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i= and j= do not match requested substring length {{ safesubst:#if:1|5}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:5|5|1}}=0) or (47=0)}}

|#default = _IN:_i2=_sublen3=5_j4=u_min=47_CORE:slen:47_i={{#if:}||{{#ifexpr:({{#if:5|1|0}} and {{#if:|1|0}})|{{#expr:47-5+{{#ifexpr:5<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:5||0|5}}<0|yes|no}}_tchk={{#if:{{#if:|{{#if:5|{{#if:|{{#ifexpr:((-+1)<>5) and (*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i= and j= do not match requested substring length {{ safesubst:#if:1|5}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:5|5|1}}=0) or (47=0)}} }}

If parameter 3 is omitted, the whole rest of the string is returned:

  • {{str mid|Abcdefghijklmnopqrstuvwxyz|15}} → {{#ifexpr:({{#if:||1}}=0) or (47=0)|
|{{#if:{{#if:15|{{#if:|{{#if:|{{#ifexpr:((-15+1)<>0) and (15*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=15 and j= do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}|{{#if:15|{{#if:|{{#if:|{{#ifexpr:((-15+1)<>0) and (15*<>0)|Error using {{[[{{#switch:

|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=15 and j= do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}

 |Abcdefghijklmnopqrstuvwxyz}}}}{{safesubst:#switch: no
|no
|n
|false
|f
|否
|0        = 
|         = 
|¬        = 
|yes
|y
|true
|t
|是
|1        = _IN:_i2=15_sublen3=u_j4=u_min=47_CORE:slen:47_i={{#if:15}|15|{{#ifexpr:({{#if:|1|0}} and {{#if:|1|0}})|{{#expr:47-+{{#ifexpr:<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:||0|}}<0|yes|no}}_tchk={{#if:{{#if:15|{{#if:|{{#if:|{{#ifexpr:((-15+1)<>0) and (15*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=15 and j= do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:||1}}=0) or (47=0)}}

|#default = _IN:_i2=15_sublen3=u_j4=u_min=47_CORE:slen:47_i={{#if:15}|15|{{#ifexpr:({{#if:|1|0}} and {{#if:|1|0}})|{{#expr:47-+{{#ifexpr:<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:||0|}}<0|yes|no}}_tchk={{#if:{{#if:15|{{#if:|{{#if:|{{#ifexpr:((-15+1)<>0) and (15*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=15 and j= do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:||1}}=0) or (47=0)}} }}

Counting from the end

By entering a negative value, the index is counted from the end:

  • {{str mid|Abcdefghijklmnopqrstuvwxyz|-7|4}} → {{#ifexpr:({{#if:4|4|1}}=0) or (47=0)|
|{{#if:{{#if:-7|{{#if:4|{{#if:|{{#ifexpr:((--7+1)<>4) and (-7*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=-7 and j= do not match requested substring length {{ safesubst:#if:1|4}}}}|}}}}}}|{{#if:-7|{{#if:4|{{#if:|{{#ifexpr:((--7+1)<>4) and (-7*<>0)|Error using {{[[{{#switch:

|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=-7 and j= do not match requested substring length {{ safesubst:#if:1|4}}}}|}}}}}}

 |Abcdefghijklmnopqrstuvwxyz}}}}{{safesubst:#switch: no
|no
|n
|false
|f
|否
|0        = 
|         = 
|¬        = 
|yes
|y
|true
|t
|是
|1        = _IN:_i2=-7_sublen3=4_j4=u_min=47_CORE:slen:47_i={{#if:-7}|-7|{{#ifexpr:({{#if:4|1|0}} and {{#if:|1|0}})|{{#expr:47-4+{{#ifexpr:4<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:4||0|4}}<0|yes|no}}_tchk={{#if:{{#if:-7|{{#if:4|{{#if:|{{#ifexpr:((--7+1)<>4) and (-7*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=-7 and j= do not match requested substring length {{ safesubst:#if:1|4}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:4|4|1}}=0) or (47=0)}}

|#default = _IN:_i2=-7_sublen3=4_j4=u_min=47_CORE:slen:47_i={{#if:-7}|-7|{{#ifexpr:({{#if:4|1|0}} and {{#if:|1|0}})|{{#expr:47-4+{{#ifexpr:4<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:4||0|4}}<0|yes|no}}_tchk={{#if:{{#if:-7|{{#if:4|{{#if:|{{#ifexpr:((--7+1)<>4) and (-7*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=-7 and j= do not match requested substring length {{ safesubst:#if:1|4}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:4|4|1}}=0) or (47=0)}} }}

  • {{str mid|Abcdefghijklmnopqrstuvwxyz|-7}} → {{#ifexpr:({{#if:||1}}=0) or (47=0)|
|{{#if:{{#if:-7|{{#if:|{{#if:|{{#ifexpr:((--7+1)<>0) and (-7*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=-7 and j= do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}|{{#if:-7|{{#if:|{{#if:|{{#ifexpr:((--7+1)<>0) and (-7*<>0)|Error using {{[[{{#switch:

|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=-7 and j= do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}

 |Abcdefghijklmnopqrstuvwxyz}}}}{{safesubst:#switch: no
|no
|n
|false
|f
|否
|0        = 
|         = 
|¬        = 
|yes
|y
|true
|t
|是
|1        = _IN:_i2=-7_sublen3=u_j4=u_min=47_CORE:slen:47_i={{#if:-7}|-7|{{#ifexpr:({{#if:|1|0}} and {{#if:|1|0}})|{{#expr:47-+{{#ifexpr:<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:||0|}}<0|yes|no}}_tchk={{#if:{{#if:-7|{{#if:|{{#if:|{{#ifexpr:((--7+1)<>0) and (-7*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=-7 and j= do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:||1}}=0) or (47=0)}}

|#default = _IN:_i2=-7_sublen3=u_j4=u_min=47_CORE:slen:47_i={{#if:-7}|-7|{{#ifexpr:({{#if:|1|0}} and {{#if:|1|0}})|{{#expr:47-+{{#ifexpr:<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:||0|}}<0|yes|no}}_tchk={{#if:{{#if:-7|{{#if:|{{#if:|{{#ifexpr:((--7+1)<>0) and (-7*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=-7 and j= do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:||1}}=0) or (47=0)}} }}

Instead if substring length, use index for last character

By using parameter |{{#if:4|4=}}n, a number, you do not ask for substring length, but the last character (as counted from the start of the input string):

  • {{str mid|Abcdefghijklmnopqrstuvwxyz|5||7}} → {{#ifexpr:({{#if:||1}}=0) or (47=0)|
|{{#if:{{#if:5|{{#if:|{{#if:7|{{#ifexpr:((7-5+1)<>) and (5*7<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j=7 do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}|{{#if:5|{{#if:|{{#if:7|{{#ifexpr:((7-5+1)<>) and (5*7<>0)|Error using {{[[{{#switch:

|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j=7 do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}

 |Abcdefghijklmnopqrstuvwxyz}}}}{{safesubst:#switch: no
|no
|n
|false
|f
|否
|0        = 
|         = 
|¬        = 
|yes
|y
|true
|t
|是
|1        = _IN:_i2=5_sublen3=_j4=7_min=7_CORE:slen:47_i={{#if:5}|5|{{#ifexpr:({{#if:|1|0}} and {{#if:7|1|0}})|{{#expr:7-+{{#ifexpr:<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:||0|}}<0|yes|no}}_tchk={{#if:{{#if:5|{{#if:|{{#if:7|{{#ifexpr:((7-5+1)<>) and (5*7<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j=7 do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:||1}}=0) or (47=0)}}

|#default = _IN:_i2=5_sublen3=_j4=7_min=7_CORE:slen:47_i={{#if:5}|5|{{#ifexpr:({{#if:|1|0}} and {{#if:7|1|0}})|{{#expr:7-+{{#ifexpr:<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:||0|}}<0|yes|no}}_tchk={{#if:{{#if:5|{{#if:|{{#if:7|{{#ifexpr:((7-5+1)<>) and (5*7<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j=7 do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:||1}}=0) or (47=0)}} }}

Spaces are kept

In the returned substring, spaces are kept:

  • >{{str mid|I like this.|2|6}}< → >{{#ifexpr:({{#if:6|6|1}}=0) or (33=0)|
|{{#if:{{#if:2|{{#if:6|{{#if:|{{#ifexpr:((-2+1)<>6) and (2*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=2 and j= do not match requested substring length {{ safesubst:#if:1|6}}}}|}}}}}}|{{#if:2|{{#if:6|{{#if:|{{#ifexpr:((-2+1)<>6) and (2*<>0)|Error using {{[[{{#switch:

|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=2 and j= do not match requested substring length {{ safesubst:#if:1|6}}}}|}}}}}}

 |I like this,}}}}{{safesubst:#switch: no
|no
|n
|false
|f
|否
|0        = 
|         = 
|¬        = 
|yes
|y
|true
|t
|是
|1        = _IN:_i2=2_sublen3=6_j4=u_min=33_CORE:slen:33_i={{#if:2}|2|{{#ifexpr:({{#if:6|1|0}} and {{#if:|1|0}})|{{#expr:33-6+{{#ifexpr:6<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:6||0|6}}<0|yes|no}}_tchk={{#if:{{#if:2|{{#if:6|{{#if:|{{#ifexpr:((-2+1)<>6) and (2*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=2 and j= do not match requested substring length {{ safesubst:#if:1|6}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:6|6|1}}=0) or (33=0)}}

|#default = _IN:_i2=2_sublen3=6_j4=u_min=33_CORE:slen:33_i={{#if:2}|2|{{#ifexpr:({{#if:6|1|0}} and {{#if:|1|0}})|{{#expr:33-6+{{#ifexpr:6<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:6||0|6}}<0|yes|no}}_tchk={{#if:{{#if:2|{{#if:6|{{#if:|{{#ifexpr:((-2+1)<>6) and (2*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=2 and j= do not match requested substring length {{ safesubst:#if:1|6}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:6|6|1}}=0) or (33=0)}} }}< But the input string is trimmed:

  • >{{str mid| I like this. |2|6}}< → >{{#ifexpr:({{#if:6|6|1}}=0) or (39=0)|
|{{#if:{{#if:2|{{#if:6|{{#if:|{{#ifexpr:((-2+1)<>6) and (2*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=2 and j= do not match requested substring length {{ safesubst:#if:1|6}}}}|}}}}}}|{{#if:2|{{#if:6|{{#if:|{{#ifexpr:((-2+1)<>6) and (2*<>0)|Error using {{[[{{#switch:

|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=2 and j= do not match requested substring length {{ safesubst:#if:1|6}}}}|}}}}}}

 |I like this.}}}}{{safesubst:#switch: no
|no
|n
|false
|f
|否
|0        = 
|         = 
|¬        = 
|yes
|y
|true
|t
|是
|1        = _IN:_i2=2_sublen3=6_j4=u_min=39_CORE:slen:39_i={{#if:2}|2|{{#ifexpr:({{#if:6|1|0}} and {{#if:|1|0}})|{{#expr:39-6+{{#ifexpr:6<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:6||0|6}}<0|yes|no}}_tchk={{#if:{{#if:2|{{#if:6|{{#if:|{{#ifexpr:((-2+1)<>6) and (2*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=2 and j= do not match requested substring length {{ safesubst:#if:1|6}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:6|6|1}}=0) or (39=0)}}

|#default = _IN:_i2=2_sublen3=6_j4=u_min=39_CORE:slen:39_i={{#if:2}|2|{{#ifexpr:({{#if:6|1|0}} and {{#if:|1|0}})|{{#expr:39-6+{{#ifexpr:6<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:6||0|6}}<0|yes|no}}_tchk={{#if:{{#if:2|{{#if:6|{{#if:|{{#ifexpr:((-2+1)<>6) and (2*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=2 and j= do not match requested substring length {{ safesubst:#if:1|6}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:6|6|1}}=0) or (39=0)}} }}<

Error messages

When the ranges (either param2 or the substring length) is out impossible in the string, an error is returned:

  • {{str mid|Abcdefghijklmnopqrstuvwxyz|30}} → {{#ifexpr:({{#if:||1}}=0) or (47=0)|
|{{#if:{{#if:30|{{#if:|{{#if:|{{#ifexpr:((-30+1)<>0) and (30*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=30 and j= do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}|{{#if:30|{{#if:|{{#if:|{{#ifexpr:((-30+1)<>0) and (30*<>0)|Error using {{[[{{#switch:

|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=30 and j= do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}

 |Abcdefghijklmnopqrstuvwxyz}}}}{{safesubst:#switch: no
|no
|n
|false
|f
|否
|0        = 
|         = 
|¬        = 
|yes
|y
|true
|t
|是
|1        = _IN:_i2=30_sublen3=u_j4=u_min=47_CORE:slen:47_i={{#if:30}|30|{{#ifexpr:({{#if:|1|0}} and {{#if:|1|0}})|{{#expr:47-+{{#ifexpr:<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:||0|}}<0|yes|no}}_tchk={{#if:{{#if:30|{{#if:|{{#if:|{{#ifexpr:((-30+1)<>0) and (30*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=30 and j= do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:||1}}=0) or (47=0)}}

|#default = _IN:_i2=30_sublen3=u_j4=u_min=47_CORE:slen:47_i={{#if:30}|30|{{#ifexpr:({{#if:|1|0}} and {{#if:|1|0}})|{{#expr:47-+{{#ifexpr:<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:||0|}}<0|yes|no}}_tchk={{#if:{{#if:30|{{#if:|{{#if:|{{#ifexpr:((-30+1)<>0) and (30*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=30 and j= do not match requested substring length {{ safesubst:#if:1|}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:||1}}=0) or (47=0)}} }}

  • {{str mid|Abcdefghijklmnopqrstuvwxyz|0|45}} → {{#ifexpr:({{#if:45|45|1}}=0) or (47=0)|
|{{#if:{{#if:5|{{#if:45|{{#if:|{{#ifexpr:((-5+1)<>45) and (5*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j= do not match requested substring length {{ safesubst:#if:1|45}}}}|}}}}}}|{{#if:5|{{#if:45|{{#if:|{{#ifexpr:((-5+1)<>45) and (5*<>0)|Error using {{[[{{#switch:

|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j= do not match requested substring length {{ safesubst:#if:1|45}}}}|}}}}}}

 |Abcdefghijklmnopqrstuvwxyz}}}}{{safesubst:#switch: no
|no
|n
|false
|f
|否
|0        = 
|         = 
|¬        = 
|yes
|y
|true
|t
|是
|1        = _IN:_i2=5_sublen3=45_j4=u_min=47_CORE:slen:47_i={{#if:5}|5|{{#ifexpr:({{#if:45|1|0}} and {{#if:|1|0}})|{{#expr:47-45+{{#ifexpr:45<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:45||0|45}}<0|yes|no}}_tchk={{#if:{{#if:5|{{#if:45|{{#if:|{{#ifexpr:((-5+1)<>45) and (5*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j= do not match requested substring length {{ safesubst:#if:1|45}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:45|45|1}}=0) or (47=0)}}

|#default = _IN:_i2=5_sublen3=45_j4=u_min=47_CORE:slen:47_i={{#if:5}|5|{{#ifexpr:({{#if:45|1|0}} and {{#if:|1|0}})|{{#expr:47-45+{{#ifexpr:45<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:45||0|45}}<0|yes|no}}_tchk={{#if:{{#if:5|{{#if:45|{{#if:|{{#ifexpr:((-5+1)<>45) and (5*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j= do not match requested substring length {{ safesubst:#if:1|45}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:45|45|1}}=0) or (47=0)}} }} The error can be suppressed by using |{{#if:ignore errors|ignore errors=}}true. A blank (empty string) will be returned:

  • {{str mid|Abcdefghijklmnopqrstuvwxyz|0|45|ignore errors=true}} → {{#ifexpr:({{#if:45|45|1}}=0) or (47=0)|
|{{#if:{{#if:5|{{#if:45|{{#if:|{{#ifexpr:((-5+1)<>45) and (5*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j= do not match requested substring length {{ safesubst:#if:1|45}}}}|}}}}}}|{{#if:5|{{#if:45|{{#if:|{{#ifexpr:((-5+1)<>45) and (5*<>0)|Error using {{[[{{#switch:

|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j= do not match requested substring length {{ safesubst:#if:1|45}}}}|}}}}}}

 |Abcdefghijklmnopqrstuvwxyz}}}}{{safesubst:#switch: no
|no
|n
|false
|f
|否
|0        = 
|         = 
|¬        = 
|yes
|y
|true
|t
|是
|1        = _IN:_i2=5_sublen3=45_j4=u_min=47_CORE:slen:47_i={{#if:5}|5|{{#ifexpr:({{#if:45|1|0}} and {{#if:|1|0}})|{{#expr:47-45+{{#ifexpr:45<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:45||0|45}}<0|yes|no}}_tchk={{#if:{{#if:5|{{#if:45|{{#if:|{{#ifexpr:((-5+1)<>45) and (5*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j= do not match requested substring length {{ safesubst:#if:1|45}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:45|45|1}}=0) or (47=0)}}

|#default = _IN:_i2=5_sublen3=45_j4=u_min=47_CORE:slen:47_i={{#if:5}|5|{{#ifexpr:({{#if:45|1|0}} and {{#if:|1|0}})|{{#expr:47-45+{{#ifexpr:45<0|-1|1}}}}|1}}}}_j=模块:Math第605行Lua错误:attempt to index field 'ext' (a nil value)_inv={{#ifexpr:{{#ifeq:45||0|45}}<0|yes|no}}_tchk={{#if:{{#if:5|{{#if:45|{{#if:|{{#ifexpr:((-5+1)<>45) and (5*<>0)|Error using {{[[{{#switch: 
|#default = Str mid 
| = 
   {{#ifeq:  | 
     | Template:Str mid            
     | Str mid      
   }}

}}|Str mid]]{{#if:||{{{arg}}}}}}}: indexes i=5 and j= do not match requested substring length {{ safesubst:#if:1|45}}}}|}}}}}}|TCHK|-}}_blankexpr:{{#expr:({{#if:45|45|1}}=0) or (47=0)}} }}

Error category

  • |{{#if:no category|no category=}}true switches off category adding.
  • |{{#if:error category|error category=}}[[Category:Your category name]] sets the category to be added when in case of an error.
Default is Category:Errors reported by Module String.

See also