aboutsummaryrefslogtreecommitdiff
path: root/files/tr/web/javascript/reference/global_objects/string/substring/index.html
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:43:23 -0500
commit218934fa2ed1c702a6d3923d2aa2cc6b43c48684 (patch)
treea9ef8ac1e1b8fe4207b6d64d3841bfb8990b6fd0 /files/tr/web/javascript/reference/global_objects/string/substring/index.html
parent074785cea106179cb3305637055ab0a009ca74f2 (diff)
downloadtranslated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.gz
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.tar.bz2
translated-content-218934fa2ed1c702a6d3923d2aa2cc6b43c48684.zip
initial commit
Diffstat (limited to 'files/tr/web/javascript/reference/global_objects/string/substring/index.html')
-rw-r--r--files/tr/web/javascript/reference/global_objects/string/substring/index.html149
1 files changed, 149 insertions, 0 deletions
diff --git a/files/tr/web/javascript/reference/global_objects/string/substring/index.html b/files/tr/web/javascript/reference/global_objects/string/substring/index.html
new file mode 100644
index 0000000000..d3a177406c
--- /dev/null
+++ b/files/tr/web/javascript/reference/global_objects/string/substring/index.html
@@ -0,0 +1,149 @@
+---
+title: String.prototype.substring()
+slug: Web/JavaScript/Reference/Global_Objects/String/substring
+translation_of: Web/JavaScript/Reference/Global_Objects/String/substring
+---
+<div>{{JSRef}}</div>
+
+<p>The <strong><code>substring()</code></strong> method returns a subset of a <code>string</code> between one index and another, or through the end of the string.</p>
+
+<h2 id="Syntax">Syntax</h2>
+
+<pre class="syntaxbox"><code><var>str</var>.substring(<var>indexStart</var>[, <var>indexEnd</var>])</code></pre>
+
+<h3 id="Parametreler">Parametreler</h3>
+
+<dl>
+ <dt><code><var>indexStart</var></code></dt>
+ <dd>An integer between <code>0</code> and the length of the string, specifying the offset into the string of the first character to include in the returned substring.</dd>
+ <dt><code>indexEnd</code></dt>
+ <dd>Optional. An integer between <code>0</code> and the length of the string, which specifies the offset into the string of the first character <strong>not</strong> to include in the returned substring.</dd>
+</dl>
+
+<h3 id="Dönen_değer">Dönen değer</h3>
+
+<p>A new string containing the extracted section of the given string.</p>
+
+<h2 id="Açıklama">Açıklama</h2>
+
+<p><code>substring()</code> extracts characters from <code>indexStart</code> up to <em>but not including</em> <code>indexEnd</code>. In particular:</p>
+
+<ul>
+ <li>If <code><var>indexStart </var></code>equals <code><var>indexEnd</var></code>, <code>substring()</code> returns an empty string.</li>
+ <li>If <code>indexEnd</code> is omitted, <code>substring()</code> extracts characters to the end of the string.</li>
+ <li>If either argument is less than 0 or is {{jsxref("NaN")}}, it is treated as if it were 0.</li>
+ <li>If either argument is greater than <code>stringName.length</code>, it is treated as if it were <code>stringName.length</code>.</li>
+</ul>
+
+<p>If <code>indexStart</code> is greater than <code>indexEnd</code>, then the effect of <code>substring()</code> is as if the two arguments were swapped; for example, <code><em>str</em>.substring(1, 0) == <em>str</em>.substring(0, 1)</code>.</p>
+
+<h2 id="Örnekler">Örnekler</h2>
+
+<h3 id="Using_substring()">Using <code>substring()</code></h3>
+
+<p>The following example uses <code>substring()</code> to display characters from the string <code>'Mozilla'</code>:</p>
+
+<pre class="brush: js">var anyString = 'Mozilla';
+
+// Displays 'Moz'
+console.log(anyString.substring(0, 3));
+console.log(anyString.substring(3, 0));
+
+// Displays 'lla'
+console.log(anyString.substring(4, 7));
+console.log(anyString.substring(4));
+console.log(anyString.substring(7, 4));
+
+// Displays 'Mozill'
+console.log(anyString.substring(0, 6));
+
+// Displays 'Mozilla'
+console.log(anyString.substring(0, 7));
+console.log(anyString.substring(0, 10));
+</pre>
+
+<h3 id="Using_substring()_with_length_property">Using <code>substring()</code> with <code>length</code> property</h3>
+
+<p>The following example uses the <code>substring()</code> method and {{jsxref("String.length", "length")}} property to extract the last characters of a particular string. This method may be easier to remember, given that you don't need to know the starting and ending indices as you would in the above examples.</p>
+
+<pre class="brush: js">// Displays 'illa' the last 4 characters
+var anyString = 'Mozilla';
+var anyString4 = anyString.substring(anyString.length - 4);
+console.log(anyString4);
+
+// Displays 'zilla' the last 5 characters
+var anyString = 'Mozilla';
+var anyString5 = anyString.substring(anyString.length - 5);
+console.log(anyString5);
+</pre>
+
+<h3 id="Replacing_a_substring_within_a_string">Replacing a substring within a string</h3>
+
+<p>The following example replaces a substring within a string. It will replace both individual characters and substrings. The function call at the end of the example changes the string <code>'Brave New World'</code> into <code>'Brave New Web'</code>.</p>
+
+<pre class="brush: js">// Replaces oldS with newS in the string fullS
+function replaceString(oldS, newS, fullS) {
+ for (var i = 0; i &lt; fullS.length; ++i) {
+ if (fullS.substring(i, i + oldS.length) == oldS) {
+ fullS = fullS.substring(0, i) + newS + fullS.substring(i + oldS.length, fullS.length);
+ }
+ }
+ return fullS;
+}
+
+replaceString('World', 'Web', 'Brave New World');
+</pre>
+
+<p>Note that this can result in an infinite loop if <code>oldS</code> is itself a substring of <code>newS</code> — for example, if you attempted to replace 'World' with 'OtherWorld' here. A better method for replacing strings is as follows:</p>
+
+<pre class="brush: js">function replaceString(oldS, newS, fullS) {
+ return fullS.split(oldS).join(newS);
+}
+</pre>
+
+<p>The code above serves as an example for substring operations. If you need to replace substrings, most of the time you will want to use {{jsxref("String.prototype.replace()")}}.</p>
+
+<h2 id="Specifications">Specifications</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('ES1')}}</td>
+ <td>{{Spec2('ES1')}}</td>
+ <td>Implemented in JavaScript 1.0.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.5.4.15', 'String.prototype.substring')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-string.prototype.substring', 'String.prototype.substring')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-string.prototype.substring', 'String.prototype.substring')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Tarayıcı_uyumluluğu">Tarayıcı uyumluluğu</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("javascript.builtins.String.substring")}}</p>
+
+<h2 id="Ayrıca_bakınız">Ayrıca bakınız</h2>
+
+<ul>
+ <li>{{jsxref("String.prototype.substr()")}}</li>
+ <li>{{jsxref("String.prototype.slice()")}}</li>
+</ul>