ଛାଞ୍ଚ:Str mid/doc
This is a documentation subpage for ଛାଞ୍ଚ:Str mid. It may contain usage information, categories and other content that is not part of the original ଛାଞ୍ଚ page. |
This template uses Lua: |
Usage
[ସମ୍ପାଦନା]Characters in the source string are counted: the first is index 1
, the last one is index 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:
{{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}} → ପ୍ରକାଶନରେ ଅସୁବିଧା: ଅଜଣା ଚିହ୍ନ "୩" ।
If parameter 2 is omitted, start is from character 1:
- {{str mid|Abcdefghijklmnopqrstuvwxyz||5}} → ପ୍ରକାଶନରେ ଅସୁବିଧା: ଅଜଣା ଚିହ୍ନ "୫" ।
If parameter 3 is omitted, the whole rest of the string is returned:
- {{str mid|Abcdefghijklmnopqrstuvwxyz|15}} → opqrstuvwxyz
Counting from the end
[ସମ୍ପାଦନା]By entering a negative value, the index is counted from the end:
- {{str mid|Abcdefghijklmnopqrstuvwxyz|-7|4}} → ପ୍ରକାଶନରେ ଅସୁବିଧା: ଅଜଣା ଚିହ୍ନ "୪" ।
- {{str mid|Abcdefghijklmnopqrstuvwxyz|-7}} → tuvwxyz
Instead if substring length, use index for last character
[ସମ୍ପାଦନା]By using parameter |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}} → efg
Spaces are kept
[ସମ୍ପାଦନା]In the returned substring, spaces are kept:
- >{{str mid|I like this.|2|6}}< → >ପ୍ରକାଶନରେ ଅସୁବିଧା: ଅଜଣା ଚିହ୍ନ "୬" ।<
But the input string is trimmed:
- >{{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:
- {{str mid|Abcdefghijklmnopqrstuvwxyz|30}} → String Module Error: String subset index out of range
- {{str mid|Abcdefghijklmnopqrstuvwxyz|0|45}} → ପ୍ରକାଶନରେ ଅସୁବିଧା: ଅଜଣା ଚିହ୍ନ "୪" ।
The error can be suppressed by using |ignore errors=true
. A blank (empty string) will be returned:
- {{str mid|Abcdefghijklmnopqrstuvwxyz|0|45|ignore errors=true}} → ପ୍ରକାଶନରେ ଅସୁବିଧା: ଅଜଣା ଚିହ୍ନ "୪" ।
Error category
[ସମ୍ପାଦନା]|no category=true
switches off category adding.|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
[ସମ୍ପାଦନା]