System.SysUtils.TStringHelper.Replace

提供: RAD Studio API Documentation
移動先: 案内検索

Delphi

function Replace(OldChar: Char; NewChar: Char): string; overload;
function Replace(OldChar: Char; NewChar: Char; ReplaceFlags: TReplaceFlags): string; overload;
function Replace(const OldValue: string; const NewValue: string): string; overload;
function Replace(const OldValue: string; const NewValue: string; ReplaceFlags: TReplaceFlags): string; overload;

プロパティ

種類 可視性 ソース ユニット
function public System.SysUtils.pas System.SysUtils TStringHelper

説明

それまでの文字または文字列を、新しく指定された文字または文字列で置換します。

 var
   MyString: String;
 
 begin
   MyString := 'This is a string.';
 
   Writeln(MyString.Replace('a', 'one'));
   Writeln(MyString.Replace('a', '1'));
 end.

出力は以下のとおりです。

 This is one string.
 This is 1 string.

Replace には 4 つのオーバーロード メソッドがあります。最初の 2 つは文字だけを、第 3、第 4 では文字列を置換します。ReplaceFlags パラメータは、rfIgnoreCaserfReplaceAll などのフラグを使用するために導入されています。

関連項目