このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
js:build-in:string [2021/09/07 11:47] tanaka [合成] |
js:build-in:string [2021/09/13 11:02] (現在) y2sunlight |
||
---|---|---|---|
行 16: | 行 16: | ||
* [[# | * [[# | ||
* [[# | * [[# | ||
+ | * [[# | ||
* [[# | * [[# | ||
* [[# | * [[# | ||
行 34: | 行 35: | ||
* [[# | * [[# | ||
* [[# | * [[# | ||
- | * [[#matchAll()|matchAll()]] | + | * [[#search()|search()]] |
* [[# | * [[# | ||
+ | * [[# | ||
* [[# | * [[# | ||
- | * [[# | ||
* [[# | * [[# | ||
- | * [[# | ||
* [[# | * [[# | ||
* [[# | * [[# | ||
行 263: | 行 263: | ||
let str = " こんにちは "; | let str = " こんにちは "; | ||
console.log(str.trimEnd()); | console.log(str.trimEnd()); | ||
+ | </ | ||
+ | |||
+ | \\ | ||
+ | === charAt() === | ||
+ | |||
+ | <code javascript> | ||
+ | let character = str.charAt(index) | ||
+ | </ | ||
+ | |||
+ | 指定された位置の文字 (UTF-16 コード 1 つから成ります) を返します。詳しくは[[https:// | ||
+ | |||
+ | <sxh javascript; | ||
+ | let str = " | ||
+ | console.log(str.charAt(6)); | ||
</ | </ | ||
行 532: | 行 546: | ||
\\ | \\ | ||
- | === matchAll() === | + | === search() === |
<code javascript> | <code javascript> | ||
- | str.matchAll(regexp) | + | str.search(regexp) |
</ | </ | ||
- | キャプチャグループを含む regexp が一致するすべてのイテレーターを返します。regexp の ''/ | + | 文字列に対してい正規表現 regexp |
<sxh javascript; | <sxh javascript; | ||
- | let str = " | + | let str = " |
- | let matches = str.matchAll(/(佐藤|鈴木|高橋)さん/g); | + | console.log(str.search(/ |
- | for(match of matches) { | + | |
- | console.log(match); | + | |
- | } | + | |
- | // 出力結果 | + | |
- | // [" | + | |
- | // [" | + | |
- | // [" | + | |
</ | </ | ||
行 569: | 行 576: | ||
\\ | \\ | ||
- | === replaceAll() === | + | === matchAll() === |
<code javascript> | <code javascript> | ||
- | const newStr = str.replaceAll(regexp|substr, newSubstr|function) | + | str.matchAll(regexp) |
</ | </ | ||
- | searchFor | + | キャプチャグループを含む regexp |
<sxh javascript; | <sxh javascript; | ||
+ | let str = " | ||
+ | let matches = str.matchAll(/ | ||
+ | for(match of matches) { | ||
+ | console.log(match); | ||
+ | } | ||
+ | // 出力結果 | ||
+ | // [" | ||
+ | // [" | ||
+ | // [" | ||
</ | </ | ||
\\ | \\ | ||
- | === search() === | + | === replaceAll() === |
<code javascript> | <code javascript> | ||
- | str.search(regexp) | + | const newStr = str.replaceAll(searchFor, replaceWith) |
</ | </ | ||
- | 文字列に対してい正規表現 | + | searchFor が現れたところすべてを replaceWith で置換するために使用します。 searchFor は文字列または正規表現であり、 replaceWith は文字列または関数です。詳しくは[[https:// |
<sxh javascript; | <sxh javascript; | ||
- | let str = " | + | let str = " |
- | console.log(str.search(/ | + | console.log(str.replaceAll(/(佐藤|鈴木|高橋)/g, ' |
</ | </ | ||
行 598: | 行 614: | ||
==== コード変換 ==== | ==== コード変換 ==== | ||
- | |||
- | === charAt() === | ||
- | |||
- | <code javascript> | ||
- | let character = str.charAt(index) | ||
- | </ | ||
- | |||
- | 指定された位置の文字 (UTF-16 コード 1 つから成ります) を返します。詳しくは[[https:// | ||
- | |||
- | <sxh javascript; | ||
- | let str = " | ||
- | console.log(str.charAt(6)); | ||
- | </ | ||
- | |||
- | \\ | ||
=== charCodeAt() === | === charCodeAt() === |