모듈:String/설명문서: 두 판 사이의 차이

편집 요약 없음
편집 요약 없음
 
(같은 사용자의 중간 판 하나는 보이지 않습니다)
26번째 줄: 26번째 줄:
또는
또는
<pre>{{#invoke:String|len|s=target_string}}</pre>
<pre>{{#invoke:String|len|s=target_string}}</pre>
<pre>{{#invoke:String|len|asdfghjkl}}</pre>
{{#invoke:String|len|asdfghjkl}}


이름 있는 변수 s 를 사용하여 함수를 불러올 경우
이름 있는 변수 s 를 사용하여 함수를 불러올 경우
36번째 줄: 39번째 줄:
사용법:
사용법:
<pre>{{#invoke:String|sub|원본 문자열|시작점|끝점}}</pre>
<pre>{{#invoke:String|sub|원본 문자열|시작점|끝점}}</pre>
or
<pre>{{#invoke:String|sub|s=원본 문자열|i=시작점|j=끝점}}</pre>
<pre>{{#invoke:String|sub|s=원본 문자열|i=시작점|j=끝점}}</pre>
<pre>{{#invoke:String|sub|asdfghjkl|4|6}}</pre>
{{#invoke:String|sub|asdfghjkl|4|6}}


변수
변수
121번째 줄: 126번째 줄:
or
or
<pre>{{#invoke:String|pos|target=target_string|pos=index_value}}</pre>
<pre>{{#invoke:String|pos|target=target_string|pos=index_value}}</pre>
<pre>{{#invoke:String|pos|asdfghjkl|3}}</pre>
{{#invoke:String|pos|asdfghjkl|3}}


변수
변수
146번째 줄: 154번째 줄:
or
or
<pre>{{#invoke:String|find|source=source_str|target=target_str|start=start_index|plain=plain_flag}}</pre>
<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}}


변수
변수
171번째 줄: 182번째 줄:


사용법:
사용법:
<pre>{{#invoke:gsub|replace|source_str|pattern_string|replace_string|replacement_count|plain_flag}}</pre>
<pre>{{#invoke:String|gsub|source_str|pattern_string|replace_string|replacement_count|plain_flag}}</pre>
or
or
<pre>{{#invoke:gsub|replace|source=source_string|pattern=pattern_string|replace=replace_string|count=replacement_count|plain=plain_flag}}</pre>
<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}}


변수
변수
205번째 줄: 219번째 줄:
사용법:
사용법:
<pre>{{#invoke:String|join|sep|one|two|three}}</pre>
<pre>{{#invoke:String|join|sep|one|two|three}}</pre>
{{#invoke:String|join|{{!}}|one|two|three}}




{{퍼온문서|문서=모듈:string|판=27795255|일부=}}
{{퍼온문서|문서=모듈:string|판=27795255|일부=}}

2021년 5월 3일 (월) 22:00 기준 최신판

이 모듈은 Lua의 기본 문자열 함수를 위키 문서에서 사용할 수 있도록 하는 모듈입니다.

Most of the functions provided here can be invoked with named parameters, unnamed parameters, or a mixture. If named parameters are used, Mediawiki will automatically remove any leading or trailing whitespace from the parameter. Depending on the intended use, it may be advantageous to either preserve or remove such whitespace.

Global options

   ignore_errors: If set to 'true' or 1, any error condition will result in
       an empty string being returned rather than an error message.
   error_category: If an error occurs, specifies the name of a category to
       include with the error message.  The default category is
       [Category:Errors reported by Module String].
   no_category: If set to 'true' or 1, no category will be added if an error
       is generated.

모듈:String/연습장에서 모듈을 테스트 해볼 수 있습니다.

len[원본 편집]

대상 문자열의 길이를 출력합니다. 사용법:

{{#invoke:String|len|target_string}}

또는

{{#invoke:String|len|s=target_string}}
{{#invoke:String|len|asdfghjkl}}

9

이름 있는 변수 s 를 사용하여 함수를 불러올 경우 대상 문자열에서 선행 또는 후행 공백이 자동 삭제됩니다.

sub[원본 편집]

이 함수는 원본 문자열에서 지정된 범위의 문자열을 반환합니다.

사용법:

{{#invoke:String|sub|원본 문자열|시작점|끝점}}
{{#invoke:String|sub|s=원본 문자열|i=시작점|j=끝점}}
{{#invoke:String|sub|asdfghjkl|4|6}}

fgh

변수

   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:

match[원본 편집]

원본 문자열에서 정규식(패턴)과 일치하는 문자열을 찾아 반환합니다.

사용법:

{{#invoke:String|match|원본 문자열|패턴(정규식)|start_index|match_number|plain_flag|nomatch_output}}

or

{{#invoke:String|match|s=원본 문자열|pattern=패턴(정규식)|start=start_index
    |match=match_number|plain=plain_flag|nomatch=nomatch_output}}

변수

   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:

pos[원본 편집]

This function returns a single character from the target string at position pos.

사용법:

{{#invoke:String|pos|target_string|index_value}}

or

{{#invoke:String|pos|target=target_string|pos=index_value}}
{{#invoke:String|pos|asdfghjkl|3}}

d

변수

   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.

사용법:

{{#invoke:String|find|source_str|target_string|start_index|plain_flag}}

or

{{#invoke:String|find|source=source_str|target=target_str|start=start_index|plain=plain_flag}}
{{#invoke:String|find|asdfghjkl|asdf}}

1

변수

   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.

사용법:

{{#invoke:String|gsub|source_str|pattern_string|replace_string|replacement_count|plain_flag}}

or

{{#invoke:String|gsub|source=source_string|pattern=pattern_string|replace=replace_string|count=replacement_count|plain=plain_flag}}
{{#invoke:String|gsub|asdfghjkl|asdf|qwer}}

qwerghjkl

변수

   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

사용법:

{{#invoke:String|escapePattern|pattern_string}}

변수

   pattern_string: The pattern string to escape.

count[원본 편집]

join[원본 편집]

Join all non empty arguments together; the first argument is the separator. 사용법:

{{#invoke:String|join|sep|one|two|three}}

one|two|three


Wikipedia-ico-48px.png
이 모듈 문서는 한국어 위키백과모듈:string 문서 27795255판에서 분기하였습니다.