Pages

Thursday, September 25, 2014

How to remove line breaks in delphi

How to remove line breaks from text in Delphi? 

You can use stringreplace 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.

Below are the sample code :
var
   before, after : string;
begin
   before:='Some text with' + #10#13 + 'line break';
   after := StringReplace(StringReplace(before, #10, ' ', [rfReplaceAll]), #13, ' ', [rfReplaceAll]);
   ShowMessage(before);   
   ShowMessage(after);
end;


No comments:

Post a Comment

Don't Forget To Join Our Community
×
Widget