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