DelphiBasics
AnsiReplaceStr
Function
Replaces a part of one string with another StrUtils unit
 function AnsiReplaceStr(const HayStack, Needle, NewNeedle string):string;
Description
The AnsiReplaceStr function replaces all occurences of the Needle string in the Haystack string with a NewNeedle string.
 
It is a Case sensitive command.
Related commands
CopyCreate a copy of part of a string or an array
InsertInsert a string into another string
MoveCopy bytes of data from a source to a destination
StringReplaceReplace one or more substrings found within a string
StuffStringReplaces a part of one string with another
 Download this web site as a Windows program.




 
Example code : A simple example
var
  haystack : AnsiString;
begin
  haystack := 'The big cat sat on the big mat';
  ShowMessage(haystack);  // Display the haystack at the start

  // Note that AnsiReplaceStr is case sensitive
  haystack := AnsiReplaceStr(haystack, 'BIG', 'LITTLE');
  ShowMessage(haystack);  // Display the haystack now

  haystack := AnsiReplaceStr(haystack, 'big', 'little');
  ShowMessage(haystack);  // Display the haystack now
end;
Show full unit code
  The big cat sat on the big mat
  The big cat sat on the big mat
  The little cat sat on the little mat
 
Delphi Programming © Neil Moffatt . All rights reserved.  |  Home Page