diff options
| author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
|---|---|---|
| committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
| commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
| tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/ja/web/javascript/reference/global_objects/string/trim | |
| parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
| download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip | |
initial commit
Diffstat (limited to 'files/ja/web/javascript/reference/global_objects/string/trim')
| -rw-r--r-- | files/ja/web/javascript/reference/global_objects/string/trim/index.html | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/files/ja/web/javascript/reference/global_objects/string/trim/index.html b/files/ja/web/javascript/reference/global_objects/string/trim/index.html new file mode 100644 index 0000000000..6719c6041d --- /dev/null +++ b/files/ja/web/javascript/reference/global_objects/string/trim/index.html @@ -0,0 +1,86 @@ +--- +title: String.prototype.trim() +slug: Web/JavaScript/Reference/Global_Objects/String/trim +tags: + - ECMAScript 5 + - JavaScript + - Method + - Prototype + - Reference + - String +translation_of: Web/JavaScript/Reference/Global_Objects/String/Trim +--- +<div>{{JSRef}}</div> + +<p><strong><code>trim()</code></strong> メソッドは、文字列の両端の空白を削除します。このコンテクストでの空白には、空白文字(スペースやタブ、ノーブレークスペースなど)とすべての改行文字(LF や CR など)を含みます。</p> + +<div>{{EmbedInteractiveExample("pages/js/string-trim.html")}}</div> + +<p class="hidden">The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone <a href="https://github.com/mdn/interactive-examples">https://github.com/mdn/interactive-examples</a> and send us a pull request.</p> + +<h2 id="Syntax" name="Syntax">構文</h2> + +<pre class="syntaxbox notranslate"><code><var>str</var>.trim()</code></pre> + +<h3 id="Return_value" name="Return_value">戻り値</h3> + +<p>呼び出し元の文字列の両端から空白を取り除いた新しい文字列です。</p> + +<h2 id="Description" name="Description">説明</h2> + +<p><code>trim()</code> メソッドは両端の空白を取り除いた文字列を返します。<code>trim()</code> はその文字列自身の値には影響を与えません(非破壊メソッド)。</p> + +<h2 id="Polyfill" name="Polyfill">Polyfill</h2> + +<p>ネイティブで使用できない場合、他のコードの前に次のコードを実行することにより <code>String.trim()</code> が使用可能になります。</p> + +<pre class="brush: js notranslate">if (!String.prototype.trim) { + String.prototype.trim = function () { + return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); + }; +} +</pre> + + +<h2 id="Examples" name="Examples">例</h2> + +<h3 id="Using_trim" name="Using_trim()"><code>trim()</code> を使う</h3> + +<p>以下の例は小文字の文字列 <code>'foo'</code> を表示します。</p> + +<pre class="brush: js notranslate">var orig = ' foo '; +console.log(orig.trim()); // 'foo' + +// 片方からだけ空白を取り除く .trim() の例。 + +var orig = 'foo '; +console.log(orig.trim()); // 'foo' +</pre> + +<h2 id="Specifications" name="Specifications">仕様</h2> + +<table class="standard-table"> + <thead> + <tr> + <th scope="col">仕様書</th> + </tr> + </thead> + <tbody> + <tr> + <td>{{SpecName('ESDraft', '#sec-string.prototype.trim', 'String.prototype.trim')}}</td> + </tr> + </tbody> +</table> + +<h2 id="Browser_compatibility" name="Browser_compatibility">ブラウザー実装状況</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.trim")}}</p> + +<h2 id="See_also" name="See_also">関連情報</h2> + +<ul> + <li>{{jsxref("String.prototype.trimStart()")}}</li> + <li>{{jsxref("String.prototype.trimEnd()")}}</li> +</ul> |
