JavaScript 文字列操作 新しいページはコチラ
提供: yonewiki
(→文字列正規表現置換(返却値は置換後文字列) replace) |
(→文字列位置による抽出(返却値は抽出文字) charAt) |
||
| 795行: | 795行: | ||
== '''文字列位置による抽出(返却値は抽出文字) charAt ''' == | == '''文字列位置による抽出(返却値は抽出文字) charAt ''' == | ||
| + | 文字列オブジェクトに対して、charAtメソッドの引数に取り出したい文字のポジションを指定すると、その一文字が取得できます。 | ||
| + | *strData = strData22.charAt(1) | ||
| + | |||
| + | |||
| + | :*第一引数:取り出したい文字の位置番号 | ||
| + | |||
| + | |||
| + | サンプルスクリプト | ||
| + | <syntaxhighlight lang="javascript" line start="1"> | ||
| + | strData22 = new String("文字列位置による抽出(charAt)"); | ||
| + | |||
| + | document.write(".charAt() : ",strData22, " ,検索結果 = ", strData22.charAt(2), "</BR>"); | ||
| + | </syntaxhighlight> | ||
| + | |||
| + | |||
| + | 表示結果: | ||
| + | |||
| + | <yjavascript> | ||
| + | strData22 = new String("文字列位置による抽出(charAt)"); | ||
| + | |||
| + | document.write(".charAt() : ",strData22, " ,検索結果 = ", strData22.charAt(2), "</BR>"); | ||
| + | </yjavascript> | ||
== '''文字列位置区間(後方位置指定可能)による抽出(返却値は抽出文字列) slice ''' == | == '''文字列位置区間(後方位置指定可能)による抽出(返却値は抽出文字列) slice ''' == | ||