Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

replaceBetween

開始点と終了点の間の部分文字列の置換

R2021b 以降

説明

newStr = replaceBetween(str,startStr,endStr,new) は、str 内の部分文字列 startStrendStr の間にある部分文字列を string new で置き換えます。replaceBetween は、startStrendStr 自体は置き換えません。new は、置き換える部分文字列と異なる文字数にできます。

newStr = replaceBetween(str,startPos,endPos,new) は、str 内の文字の位置 startPosendPos の間にある部分文字列を、これらの位置にある文字も含めて置き換えます。

newStr = replaceBetween(___,Boundaries=bounds) は、演算子が置き換える部分文字列に、前述の構文で指定した境界を含めるか、または除外します。bounds"inclusive" または "exclusive" として指定します。

メモ

replaceBetween 演算子は、C をアクション言語として使用する Stateflow® チャートではサポートされません。

すべて展開する

部分文字列を置換して、string "Hello, Mars!" を作成します。既定では、replaceBetween は境界の部分文字列を置き換えません。

str = "Hello, world!";
newStr = replaceBetween(str,"Hello, ","!","Mars");

Stateflow chart that uses the replaceBetween operator in a state.

境界の部分文字列を置き換えるには、代わりにオプション Boundaries="inclusive" を使用します。

str = "Hello, world!";
newStr = replaceBetween(str,"w","d","Mars",Boundaries="inclusive");

Stateflow chart that uses the replaceBetween operator in a state.

部分文字列を置換して、string "Hello, Mars!" を作成します。既定では、replaceBetween は境界の文字を置き換えます。

str = "Hello, world!";
newStr = replaceBetween(str,8,12,"Mars");

Stateflow chart that uses the replaceBetween operator in a state.

境界の文字が置き換えられないようにするには、代わりにオプション Boundaries="exclusive" を使用します。

str = "Hello, world!";
newStr = replaceBetween(str,7,13,"Mars",Boundaries="exclusive");

Stateflow chart that uses the replaceBetween operator in a state.

入力引数

すべて展開する

入力 string。string スカラーとして指定します。リテラル文字列は二重引用符で囲みます。

例: "Hello"

先頭の部分文字列。string スカラーとして指定します。リテラル文字列は二重引用符で囲みます。

例: "Hello"

末尾の部分文字列。string スカラーとして指定します。リテラル文字列は二重引用符で囲みます。

例: "Hello"

先頭の文字の位置。正の整数として指定します。

末尾の文字の位置。正の整数として指定します。

新しい部分文字列。string スカラーとして指定します。リテラル文字列は二重引用符で囲みます。

例: "Hello"

境界のタイプ。"inclusive" または "exclusive" として指定します。bounds"exclusive" に設定すると、replaceBetween は、境界間にあるテキストのみを置き換えます。bounds"inclusive" に設定すると、replaceBetween は、境界自体も置き換えます。

制限

バージョン履歴

R2021b で導入