Specialised String Routines

You can see the many string routines available in the Lazarus documentation of SysUtils and StrUtils. Also, the interface section of the source code for each unit provides useful information about the use of the routines. For Delphi users, the routines are well documented in the help files. As usual, DelphiBasics is helpful.

The following program illustrates the use of ansiReplaceStr.

program ReplaceDemo;
  {$APPTYPE CONSOLE}
uses
  SysUtils, StrUtils;
var
  TestString, SearchString, ReplaceString: string;
begin
  writeln('Here is one we prepared earlier:', #13#10);
  TestString := 'The quick brown fox jumped over the lazy dog.';
  SearchString := 'lazy';
  ReplaceString := 'motivationally challenged';
  TestString := ansiReplaceStr(TestString, SearchString, ReplaceString);
  writeln(TestString);
  writeln;
  writeln('Here is one for you to try.  The starting sentence is:');
  TestString := 'Manchester United will win the Premiership next year.';
  writeln(TestString);
  write('Please enter the string to be replaced. ');
  readln(SearchString);
  write('Please enter the string to replace ',SearchString, ' with. ');
  readln(ReplaceString);
  TestString := ansiReplaceStr(TestString, SearchString, ReplaceString);
  writeln(TestString);
  readln;
end.  
 

In the next section we demonstrate the use of:

Programming - a skill for life!

Introduction to string routines such as the concat function