Home  |  Delphi .net Home  |  system.String  |  Replace Method
Replace  
Method  
Replaces all occurences of a string with another string
String Class
system NameSpace
CF1.  Function Replace ( OldValue:CharOldValue : Char; NewValue : Char; ) : String ;
CF2.  Function Replace ( OldValue:StringOldValue : String; NewValue : String; ) : String;
CF : Methods with this mark are Compact Framework Compatible
Description
Replaces all occurences of a single character, or a sequence of characters : OldValue with a new character or string : NewValue in the current string.
 
It is a case sensitive method.
Notes
Like a lot of string methods, the string object itself is not affected - the modified string is returned for assignment.
Microsoft MSDN Links
system
system.String
 
 
A simple example
program Project1;
{$APPTYPE CONSOLE}

var
  strA, strB     : String;

begin
  strA := 'First is not worst';

  strB := strA.Replace('rst', 'rm');

  Console.WriteLine('strA = ' + strA);
  Console.WriteLine('Replacing ''rst'' with ''rm''');
  Console.WriteLine('strB = ' + strB);

  Console.ReadLine;
end.
Show full unit code
  strA = First is not worst
  Replacing 'rst' with 'rm'
  strB = Firm is not worm
 
 
Delphi Programming © Neil Moffatt All rights reserved.  |  Contact the author