Template:Str_mid
[Wikipedia|▼Menu]
.mw-parser-output .documentation,.mw-parser-output .documentation-metadata{border:1px solid #a2a9b1;background-color:#ecfcf4;clear:both}.mw-parser-output .documentation{margin:1em 0 0 0;padding:1em}.mw-parser-output .documentation-metadata{margin:0.2em 0;font-style:italic;padding:0.4em 1em}.mw-parser-output .documentation-startbox{padding-bottom:3px;border-bottom:1px solid #aaa;margin-bottom:1ex}.mw-parser-output .documentation-heading{font-weight:bold;font-size:125%}.mw-parser-output .documentation-clear{clear:both}.mw-parser-output .documentation-toolbar{font-style:normal;font-size:85%} テンプレートの解説[表示] [編集] [履歴] [キャッシュを破棄].mw-parser-output .ombox{margin:4px 0;border-collapse:collapse;border:1px solid #a2a9b1;background-color:#f8f9fa;box-sizing:border-box}.mw-parser-output .ombox.mbox-small{font-size:88%;line-height:1.25em}.mw-parser-output .ombox-speedy{border:2px solid #b32424;background-color:#fee7e6}.mw-parser-output .ombox-delete{border:2px solid #b32424}.mw-parser-output .ombox-content{border:1px solid #f28500}.mw-parser-output .ombox-style{border:1px solid #fc3}.mw-parser-output .ombox-move{border:1px solid #9932cc}.mw-parser-output .ombox-protection{border:2px solid #a2a9b1}.mw-parser-output .ombox .mbox-text{border:none;padding:0.25em 0.9em;width:100%;font-size:90%}.mw-parser-output .ombox .mbox-image{border:none;padding:2px 0 2px 0.9em;text-align:center}.mw-parser-output .ombox .mbox-imageright{border:none;padding:2px 0.9em 2px 0;text-align:center}.mw-parser-output .ombox .mbox-empty-cell{border:none;padding:0;width:1px}.mw-parser-output .ombox .mbox-invalid-type{text-align:center}@media(min-width:720px){.mw-parser-output .ombox{margin:4px 10%}.mw-parser-output .ombox.mbox-small{clear:right;float:right;margin:4px 0 4px 1em;width:238px}}

このテンプレートは4,000以上のページで使われています。
余計な混乱やサーバーへの負荷を避けるために、どんな変更でも最初はテンプレートのサンドボックス・サブページテストケース・サブページもしくはあなた自身の利用者スペースページで試すべきです。そうすれば、試した変更を1度の編集でこのテンプレートに加えることができます。しかし、最初にあなたの提案した変更を、この項目のノートで議論するようにお願いします。

Luaモジュールを使用しています:

Module:String


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}} → efg

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

{{str mid|Abcdefghijklmnopqrstuvwxyz||5}} → Abcde

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}} → tuvw

{{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}}< → >like<

But the input string is trimmed:

>{{str mid。 I like this. |2|6}}< → >like<

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のエラー: String subset index out of range

{{str mid|Abcdefghijklmnopqrstuvwxyz|0|45}} → efghijklmnopqrstuvwxyz

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}} → 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 mid}} 文字列のうち、指定した位置からはじまる指定した長さの文字列を返す。1文字目は1として数える。
{{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文字を除去する。


内容別

{{trim}} 先頭と末尾のホワイトスペースを除去する。
{{str letter/trim}} 文字列のうち、最初のアルファベットからはじめて、アルファベット以外が現れるまでの文字を返す。
{{str number/trim}} 文字列のうち、最初の数字からはじめて、数字以外が現れるまでの文字を返す。
{{trim quotes}} 先頭と末尾に引用符のペアがある場合、それらを除去する。ホワイトスペースも併せて除去する。
{{first word}} 文字列のうち、最初のスペースまでの文字を返す。
{{remove first word}} 文字列のうち、最初のスペースまでの文字を除去する。
{{last word}} 文字列のうち、最後のスペース以降の文字を返す。
{{remove last word}} 文字列のうち、最後のスペース以降の文字を除去する。
{{Plain text}} 文字列からウィキテキストマークアップを除去して返す。


次ページ
記事の検索
おまかせリスト
▼オプションを表示
ブックマーク登録
mixiチェック!
Twitterに投稿
オプション/リンク一覧
話題のニュース
列車運行情報
暇つぶしWikipedia

Size:13 KB
出典: フリー百科事典『ウィキペディア(Wikipedia)
担当:undef