VBScript Replace 関数
定義と使用法
Replace 関数は、指定された回数で文字列を別の文字列に置き換えることができます。
文法
Replace(string,find,replacewith[,start[,count[,compare]]])
引数 |
説明 |
string |
必要です。検索する必要がある文字列です。 |
find |
必要です。置き換える文字列の部分です。 |
replacewith |
必要です。置き換える子文字列です。 |
start |
選択可能です。開始位置を指定します。デフォルトは 1 です。 |
count |
オプション。指定する置換の回数を指定します。デフォルトは -1 で、すべての可能な置換を行います。 |
compare |
オプション。使用する文字列比較の種類を指定します。デフォルトは 0 です。 |
パラメータ compare の値:
定数 |
値 |
説明 |
vbBinaryCompare |
0 |
バイナリ比較を実行します。 |
vbTextCompare |
1 |
テキスト比較を実行します。 |
Replace が返す可能性のある値:
パラメータの可能な値 |
Replace が返す値 |
expression が長さゼロ |
長さゼロの文字列 ("")。 |
expression が Null |
エラー。 |
find パラメータが長さゼロ |
expression のコピー。 |
replacewith パラメータが長さゼロ |
find パラメータで指定されたすべての内容を削除した expression のコピー。 |
start > Len(expression) |
長さゼロの文字列。 |
count が 0 |
expression のコピー。 |
インスタンス
例 1
dim txt
txt="これは美しい日です!"
document.write(Replace(txt,"beautiful","horrible"))
出力:
これはひどい日です!