최신판 |
당신의 편집 |
19번째 줄: |
19번째 줄: |
|
| |
|
| [[모듈:String/연습장]]에서 모듈을 테스트 해볼 수 있습니다. | | [[모듈:String/연습장]]에서 모듈을 테스트 해볼 수 있습니다. |
|
| |
| === len ===
| |
| 대상 문자열의 길이를 출력합니다.
| |
| 사용법:
| |
| <pre>{{#invoke:String|len|target_string}}</pre>
| |
| 또는
| |
| <pre>{{#invoke:String|len|s=target_string}}</pre>
| |
|
| |
| <pre>{{#invoke:String|len|asdfghjkl}}</pre>
| |
| {{#invoke:String|len|asdfghjkl}}
| |
|
| |
| 이름 있는 변수 s 를 사용하여 함수를 불러올 경우
| |
| 대상 문자열에서 선행 또는 후행 공백이 자동 삭제됩니다.
| |
|
| |
| === sub ===
| |
|
| |
| 이 함수는 원본 문자열에서 지정된 범위의 문자열을 반환합니다.
| |
|
| |
| 사용법:
| |
| <pre>{{#invoke:String|sub|원본 문자열|시작점|끝점}}</pre>
| |
| <pre>{{#invoke:String|sub|s=원본 문자열|i=시작점|j=끝점}}</pre>
| |
|
| |
| <pre>{{#invoke:String|sub|asdfghjkl|4|6}}</pre>
| |
| {{#invoke:String|sub|asdfghjkl|4|6}}
| |
|
| |
| 변수
| |
| s: 원본 문자열
| |
| i: 반환할 문자열의 시작점, 기본값은 1
| |
| j: 반환할 문자열의 끝점, 기본값은 문자열 끝까지
| |
|
| |
| 문자열의 첫 번째 문자의 인덱스는 1입니다. i나 j가 음수이면 문자열의 맨 뒤에서부터 위치가 계산됩니다. 예를 들어 abcd의 인덱스 1은 a, 인덱스 -1은 d입니다.
| |
|
| |
| 인덱스가 문자열의 범위를 벗어나면 오류를 반환합니다.
| |
|
| |
| === _match ===
| |
| 사용법 : require("Module:String")._match
| |
| strmatch = require("Module:String")._match
| |
| sresult = strmatch( s, pattern, start, match, plain, nomatch )
| |
|
| |
| 다른 모듈에 포함해서 사용하는 함수입니다.
| |
|
| |
| 변수
| |
| s: 대상 문자열
| |
| pattern: 대상 문자열에서 찾을 문자열이나 정규식(패턴)을 입력합니다.
| |
| start: The index within the source string to start the search. The first
| |
| character of the string has index 1. Defaults to 1.
| |
| match: In some cases it may be possible to make multiple matches on a single
| |
| string. This specifies which match to return, where the first match is
| |
| match= 1. If a negative number is specified then a match is returned
| |
| counting from the last match. Hence match = -1 is the same as requesting
| |
| the last match. Defaults to 1.
| |
| plain: A flag indicating that the pattern should be understood as plain
| |
| text. Defaults to false.
| |
| nomatch: If no match is found, output the "nomatch" value rather than an error.
| |
|
| |
| For information on constructing Lua patterns, a form of [regular expression], see:
| |
|
| |
| * http://www.lua.org/manual/5.1/manual.html#5.4.1
| |
| * http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Patterns
| |
| * http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Ustring_patterns
| |
|
| |
| === match ===
| |
|
| |
| 원본 문자열에서 정규식(패턴)과 일치하는 문자열을 찾아 반환합니다.
| |
|
| |
| 사용법:
| |
| <pre>{{#invoke:String|match|원본 문자열|패턴(정규식)|start_index|match_number|plain_flag|nomatch_output}}</pre>
| |
| or
| |
| <pre>{{#invoke:String|match|s=원본 문자열|pattern=패턴(정규식)|start=start_index
| |
| |match=match_number|plain=plain_flag|nomatch=nomatch_output}}</pre>
| |
|
| |
| 변수
| |
| s: 원본 문자열
| |
| pattern: 원본 문자열에서 찾을 문자열/패턴
| |
| start: 검색을 시작할 위치. 첫 번째 문자의 인덱스는 1입니다. 기본값은 1.
| |
| match: In some cases it may be possible to make multiple matches on a single
| |
| string. This specifies which match to return, where the first match is
| |
| match= 1. If a negative number is specified then a match is returned
| |
| counting from the last match. Hence match = -1 is the same as requesting
| |
| the last match. Defaults to 1.
| |
| plain: A flag indicating that the pattern should be understood as plain
| |
| text. Defaults to false.
| |
| nomatch: If no match is found, output the "nomatch" value rather than an error.
| |
|
| |
| If invoked using named 변수, Mediawiki will automatically remove any leading or
| |
| trailing whitespace from each string. In some circumstances this is desirable, in
| |
| other cases one may want to preserve the whitespace.
| |
|
| |
| If the match_number or start_index are out of range for the string being queried, then
| |
| this function generates an error. An error is also generated if no match is found.
| |
| If one adds the parameter ignore_errors=true, then the error will be suppressed and
| |
| an empty string will be returned on any failure.
| |
|
| |
| For information on constructing Lua patterns, a form of [regular expression], see:
| |
|
| |
| * http://www.lua.org/manual/5.1/manual.html#5.4.1
| |
| * http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Patterns
| |
| * http://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Ustring_patterns
| |
|
| |
| === pos ===
| |
|
| |
| This function returns a single character from the target string at position pos.
| |
|
| |
| 사용법:
| |
| <pre>{{#invoke:String|pos|target_string|index_value}}</pre>
| |
| or
| |
| <pre>{{#invoke:String|pos|target=target_string|pos=index_value}}</pre>
| |
|
| |
| <pre>{{#invoke:String|pos|asdfghjkl|3}}</pre>
| |
| {{#invoke:String|pos|asdfghjkl|3}}
| |
|
| |
| 변수
| |
| target: The string to search
| |
| pos: The index for the character to return
| |
|
| |
| If invoked using named 변수, Mediawiki will automatically remove any leading or
| |
| trailing whitespace from the target string. In some circumstances this is desirable, in
| |
| other cases one may want to preserve the whitespace.
| |
|
| |
| The first character has an index value of 1.
| |
|
| |
| If one requests a negative value, this function will select a character by counting backwards
| |
| from the end of the string. In other words pos = -1 is the same as asking for the last character.
| |
|
| |
| A requested value of zero, or a value greater than the length of the string returns an error.
| |
|
| |
| === find ===
| |
|
| |
| This function allows one to search for a target string or pattern within another
| |
| string.
| |
|
| |
| 사용법:
| |
| <pre>{{#invoke:String|find|source_str|target_string|start_index|plain_flag}}</pre>
| |
| or
| |
| <pre>{{#invoke:String|find|source=source_str|target=target_str|start=start_index|plain=plain_flag}}</pre>
| |
|
| |
| <pre>{{#invoke:String|find|asdfghjkl|asdf}}</pre>
| |
| {{#invoke:String|find|asdfghjkl|asdf}}
| |
|
| |
| 변수
| |
| source: The string to search
| |
| target: The string or pattern to find within source
| |
| start: The index within the source string to start the search, defaults to 1
| |
| plain: Boolean flag indicating that target should be understood as plain
| |
| text and not as a Lua style regular expression, defaults to true
| |
|
| |
| If invoked using named 변수, Mediawiki will automatically remove any leading or
| |
| trailing whitespace from the parameter. In some circumstances this is desirable, in
| |
| other cases one may want to preserve the whitespace.
| |
|
| |
| This function returns the first index >= "start" where "target" can be found
| |
| within "source". Indices are 1-based. If "target" is not found, then this
| |
| function returns 0. If either "source" or "target" are missing / empty, this
| |
| function also returns 0.
| |
|
| |
| This function should be safe for UTF-8 strings.
| |
|
| |
| === gsub ===
| |
|
| |
| This function allows one to replace a target string or pattern within another
| |
| string.
| |
|
| |
| 사용법:
| |
| <pre>{{#invoke:String|gsub|source_str|pattern_string|replace_string|replacement_count|plain_flag}}</pre>
| |
| or
| |
| <pre>{{#invoke:String|gsub|source=source_string|pattern=pattern_string|replace=replace_string|count=replacement_count|plain=plain_flag}}</pre>
| |
|
| |
| <pre>{{#invoke:String|gsub|asdfghjkl|asdf|qwer}}</pre>
| |
| {{#invoke:String|gsub|asdfghjkl|asdf|qwer}}
| |
|
| |
| 변수
| |
| source: The string to search
| |
| pattern: The string or pattern to find within source
| |
| replace: The replacement text
| |
| count: The number of occurences to replace, defaults to all.
| |
| plain: Boolean flag indicating that pattern should be understood as plain
| |
| text and not as a Lua style regular expression, defaults to true
| |
|
| |
| === rep ===
| |
| Repeat
| |
|
| |
| === escapePattern ===
| |
|
| |
| This function escapes special characters from a Lua string pattern. See [1]
| |
| for details on how patterns work.
| |
|
| |
| [1] https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Patterns
| |
|
| |
| 사용법:
| |
| <pre>{{#invoke:String|escapePattern|pattern_string}}</pre>
| |
|
| |
| 변수
| |
| pattern_string: The pattern string to escape.
| |
| === count ===
| |
|
| |
| === join ===
| |
|
| |
| Join all non empty arguments together; the first argument is the separator.
| |
| 사용법:
| |
| <pre>{{#invoke:String|join|sep|one|two|three}}</pre>
| |
| {{#invoke:String|join|{{!}}|one|two|three}}
| |
|
| |
|
| |
|
| {{퍼온문서|문서=모듈:string|판=27795255|일부=}} | | {{퍼온문서|문서=모듈:string|판=27795255|일부=}} |