Home About project

Remove line breaks with Delphi

If you need to remove line breaks from text with Delphi you can use next next text function:

  • function StringReplace (const SourceString, OldPattern, NewPattern : string; Flags : TReplaceFlags) : string;

The StringReplace function replaces the first or all occurences of a substring OldPattern in SourceString with NewPattern according to Flags settings. The changed string is returned.

    The Flags may be none, one, or both of these set values:
  • rfReplaceAll : Change all occurrences
  • rfIgnoreCase : Ignore case when searching

These values are specified in square brackets.

To remove line breaks using Delphi see example:

uses SysUtils;

   before, after : string;
   before:='Some text with' + #10#13 + 'line break';
   //Change line break #10 and #13 on a space
   after := StringReplace(StringReplace(before, #10, ' ', [rfReplaceAll]), #13, ' ', [rfReplaceAll]);
   //Output: Some text with
   //line break
   //Output: Some text with line break