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