Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make String into only 1 line

Tags:

string

delphi

I have an output that is basically a paragraph and when I try to search the string for a substring, if that substring is split up it doesnt' work. How can I make the paragraph string into just 1 line?

Example string:

I have an output that is basically a paragraph and when I try 
to search the string for a substring, if that substring is split up it 
doesn't work. How can I make the paragraph string into just 1 line?

substring: "it doesn't work"

When I try to search for that substring, it doesn't return true.

like image 455
Eugene K Avatar asked Jul 12 '11 17:07

Eugene K


1 Answers

It seems like you want to treat newlines as spaces. Writing efficient search algorithms is not trivial, but an approach that works and answers the question in your title, is

str := StringReplace(str, sLineBreak, ' ', [rfReplaceAll]);

That is, we simply replace all linebreaks with spaces. Without the magic constants, this is

str := StringReplace(str, #13#10, #32, [rfReplaceAll]);

Perhaps there are already spaces between the words, in addition to the linebreaks? Then just remove the linebreaks, without adding spaces:

str := StringReplace(str, #13#10, '', [rfReplaceAll]);
like image 67
Andreas Rejbrand Avatar answered Sep 24 '22 00:09

Andreas Rejbrand