aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/javascript/reference/global_objects/string/substr
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:42:17 -0500
commitda78a9e329e272dedb2400b79a3bdeebff387d47 (patch)
treee6ef8aa7c43556f55ddfe031a01cf0a8fa271bfe /files/ko/web/javascript/reference/global_objects/string/substr
parent1109132f09d75da9a28b649c7677bb6ce07c40c0 (diff)
downloadtranslated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.gz
translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.tar.bz2
translated-content-da78a9e329e272dedb2400b79a3bdeebff387d47.zip
initial commit
Diffstat (limited to 'files/ko/web/javascript/reference/global_objects/string/substr')
-rw-r--r--files/ko/web/javascript/reference/global_objects/string/substr/index.html131
1 files changed, 131 insertions, 0 deletions
diff --git a/files/ko/web/javascript/reference/global_objects/string/substr/index.html b/files/ko/web/javascript/reference/global_objects/string/substr/index.html
new file mode 100644
index 0000000000..39fe5e126b
--- /dev/null
+++ b/files/ko/web/javascript/reference/global_objects/string/substr/index.html
@@ -0,0 +1,131 @@
+---
+title: String.prototype.substr()
+slug: Web/JavaScript/Reference/Global_Objects/String/substr
+tags:
+ - Deprecated
+ - JavaScript
+ - Method
+ - Prototype
+ - Reference
+ - String
+translation_of: Web/JavaScript/Reference/Global_Objects/String/substr
+---
+<div>{{JSRef}}</div>
+
+<div> </div>
+
+<div class="warning">
+<p>경고: 엄밀히 말해서 <code>String.prototype.substr()</code> 메서드가 더 이상 사용되지 않는, 즉 "웹 표준에서 제거된" 건 아닙니다. 그러나 <code>substr()</code>이 포함된 ECMA-262 표준의 <a href="https://www.ecma-international.org/ecma-262/9.0/index.html#sec-additional-ecmascript-features-for-web-browsers">부록 B</a>는 다음과 같이 명시하고 있습니다.</p>
+
+<blockquote>… 본 부록이 포함한 모든 언어 기능과 행동은 하나 이상의 바람직하지 않은 특징을 갖고 있으며 사용처가 없어질 경우 명세에서 제거될 것입니다. …<br>
+… 프로그래머는 새로운 ECMAScript 코드를 작성할 때 본 부록이 포함한 기능을 사용하거나 존재함을 가정해선 안됩니다. …</blockquote>
+</div>
+
+<p><strong><code>substr()</code></strong> 메서드는 문자열에서 특정 위치에서 시작하여 특정 문자 수 만큼의 문자들을 반환합니다.</p>
+
+<p>{{EmbedInteractiveExample("pages/js/string-substr.html")}}</p>
+
+<h2 id="구문">구문</h2>
+
+<pre class="syntaxbox"><var>str</var>.substr(<var>start</var>[, <var>length</var>])</pre>
+
+<h3 id="매개변수">매개변수</h3>
+
+<dl>
+ <dt><code>start</code></dt>
+ <dd>추출하고자 하는 문자들의 시작위치입니다. 만약 음수가 주어진다면, <code>문자열총길이 + start</code>의 값으로 취급합니다. 예를 들면, <code>start</code>에 -3을 설정하면, 자동적으로 <code>문자열총길이 - 3</code>으로 설정하게 됩니다. </dd>
+ <dt><code>length</code></dt>
+ <dd>옵션값. 추출할 문자들의 총 숫자.</dd>
+</dl>
+
+<h2 id="설명">설명</h2>
+
+<p><code>start</code>는 문자 인덱스입니다. 문자열에서 첫 번째 문자의 인덱스는 0이며, 마지막 문자의 인덱스는 문자열 전체 길이에서 1을 뺀 값입니다. <code>substr()</code>는<code> start</code>에서 문자들을 추출을 시작하여 <code>length</code>만큼 문자들을 수집합니다.</p>
+
+<p>만약 <code>start</code> 값이 양수이고 문자열 전체 길이보다 크거가 같을 경우, <code>substr()</code>은 빈 문자열을 반환합니다. </p>
+
+<p>만약 <code>start</code>가 음수이면, <code>substr()</code>은 문자열 끝에서 <code>start</code> 숫자만큼 뺀 곳에서 시작하게 됩니다. 만약 <code>start</code>가 음수이고 절대값이 문자열 전체보다 크다면, <code>substr()</code>은 문자열의 0 인덱스부터 시작하게 됩니다. (주의: <code>start</code>의 음수값은 Microsoft JScript에서는 위의 설명과 같이 동작하지 않습니다.)</p>
+
+<p>만약 <code>length</code>가 0 혹은 음수이면, <code>substr()</code>은 빈 문자열을 반환합니다. 만약 <code>length</code>가 생략되면, <code>substr()</code>은 문자열의 끝까지 추출하여 반환합니다. </p>
+
+<h2 id="예제">예제</h2>
+
+<h3 id="substr()_사용하기"><code>substr()</code> 사용하기</h3>
+
+<pre class="brush: js">var str = 'abcdefghij';
+
+console.log('(1, 2): ' + str.substr(1, 2)); // '(1, 2): bc'
+console.log('(-3, 2): ' + str.substr(-3, 2)); // '(-3, 2): hi'
+console.log('(-3): ' + str.substr(-3)); // '(-3): hij'
+console.log('(1): ' + str.substr(1)); // '(1): bcdefghij'
+console.log('(-20, 2): ' + str.substr(-20, 2)); // '(-20, 2): ab'
+console.log('(20, 2): ' + str.substr(20, 2)); // '(20, 2): '
+</pre>
+
+<h2 id="폴리필">폴리필</h2>
+
+<p>Microsoft의 JScript는 시작 인덱스에서 음수값을 지원하지 않습니다. 만약 여러분이 이렇게 동작하길 원한다면, 아래 코드를 사용하여 해결할 수 있습니다: </p>
+
+<pre class="brush: js">// only run when the substr() function is broken
+if ('ab'.substr(-1) != 'b') {
+ /**
+ * Get the substring of a string
+ * @param {integer} start where to start the substring
+ * @param {integer} length how many characters to return
+ * @return {string}
+ */
+ String.prototype.substr = function(substr) {
+ return function(start, length) {
+ // call the original method
+ return substr.call(this,
+ // did we get a negative start, calculate how much it is from the beginning of the string
+ // adjust the start parameter for negative value
+ start &lt; 0 ? this.length + start : start,
+ length)
+ }
+ }(String.prototype.substr);
+}
+</pre>
+
+<h2 id="명세">명세</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES3')}}</td>
+ <td>{{Spec2('ES3')}}</td>
+ <td>Defined in the (informative) Compatibility Annex B. Implemented in JavaScript 1.0.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-B.2.3', 'String.prototype.substr')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td>Defined in the (informative) Compatibility Annex B</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-string.prototype.substr', 'String.prototype.substr')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td>Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-string.prototype.substr', 'String.prototype.substr')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td>Defined in the (normative) Annex B for Additional ECMAScript Features for Web Browsers</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="브라우저_호환성">브라우저 호환성</h2>
+
+<div>{{Compat("javascript.builtins.String.substr")}}</div>
+
+<h2 id="같이_보기">같이 보기</h2>
+
+<ul>
+ <li>{{jsxref("String.prototype.slice()")}}</li>
+ <li>{{jsxref("String.prototype.substring()")}}</li>
+</ul>