このテンプレートは4,000以上のページで使われています。
余計な混乱やサーバーへの負荷を避けるために、どんな変更でも最初はテンプレートのサンドボックス・サブページ、テストケース・サブページもしくはあなた自身の利用者スペースのページで試すべきです。そうすれば、試した変更を1度の編集でこのテンプレートに加えることができます。しかし、最初にあなたの提案した変更を、この項目のノートで議論するようにお願いします。
Luaモジュールを使用しています: 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. If parameter 2 is omitted, start is from character 1: If parameter 3 is omitted, the whole rest of the string is returned: By entering a negative value, the index is counted from the end: 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): In the returned substring, spaces are kept: But the input string is trimmed: When the ranges (either param2 or the substring length) is out impossible in the string, an error is returned: The error can be suppressed by using |ignore errors=true. A blank (empty string) will be returned: 文字列のトリミング(英語版 長さ別 {{str mid {{trim}} 先頭と末尾のホワイトスペースを除去する。
Module:String
Usage
{{str mid|Abcdefghijklmnopqrstuvwxyz|5|3}} → efg
{{str mid|Abcdefghijklmnopqrstuvwxyz||5}} → Abcde
{{str mid|Abcdefghijklmnopqrstuvwxyz|15}} → opqrstuvwxyz
Counting from the end
{{str mid|Abcdefghijklmnopqrstuvwxyz|-7|4}} → tuvw
{{str mid|Abcdefghijklmnopqrstuvwxyz|-7}} → tuvwxyz
Instead if substring length, use index for last character
{{str mid|Abcdefghijklmnopqrstuvwxyz|5||7}} → efg
Spaces are kept
>{{str mid|I like this.|2|6}}< → >like<
>{{str mid。 I like this. |2|6}}< → >like<
Error messages
{{str mid|Abcdefghijklmnopqrstuvwxyz|30}} → モジュールStringのエラー: String subset index out of range
{{str mid|Abcdefghijklmnopqrstuvwxyz|0|45}} → efghijklmnopqrstuvwxyz
{{str mid|Abcdefghijklmnopqrstuvwxyz|0|45|ignore errors=true}} → efghijklmnopqrstuvwxyz
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
表
話
編
歴
文字列処理テンプレート
{{str sub old}} 文字列のうち、指定した位置からはじまる指定した長さの文字列を返す。1文字目は0として数える。
{{str sub new}} 文字列のX文字目からY文字目までを返す。
{{str index}} 文字列のX文字目を返す。
{{trunc}} 文字列の先頭X文字を返す。長さが未指定か数字以外の場合は文字列をそのまま返す。
{{str left}} 文字列の先頭X文字を返す。長さが未指定の場合は先頭1文字目を、数字以外の場合は空白を返す。
{{str right}} 文字列の先頭X文字を除去する。
{{str rightc}} 文字列の末尾から数えてX文字目までを返す。入力文字列が空白の場合に返す文字列を指定できる。
{{str rightmost}} 文字列の末尾から数えてX文字目までを返す。
{{str crop}} 文字列の末尾X文字を除去する。
内容別
{{str letter/trim}} 文字列のうち、最初のアルファベットからはじめて、アルファベット以外が現れるまでの文字を返す。
{{str number/trim}} 文字列のうち、最初の数字からはじめて、数字以外が現れるまでの文字を返す。
{{trim quotes}} 先頭と末尾に引用符のペアがある場合、それらを除去する。ホワイトスペースも併せて除去する。
{{first word}} 文字列のうち、最初のスペースまでの文字を返す。
{{remove first word
{{last word}} 文字列のうち、最後のスペース以降の文字を返す。
{{remove last word}} 文字列のうち、最後のスペース以降の文字を除去する。
{{Plain text}} 文字列からウィキテキストマークアップを除去して返す。