Max Carroll
Max Carroll

Reputation: 4839

How do I do a multiple line verbatim string in Delphi/Pascal

In c# you can use multiline literal strings to have a string which spans a physical line break in the sourcecode e.g.

var someHtml = @"<table width="100%" border="0" cellspacing="0" cellpadding="5" align="center" class="txsbody">
    <tbody>
        <tr>
            <td width="15%" class="ttxb">&nbsp;</td>
            <td width="85%" class="ttxb"><b>COMPANY NAME</b></td>
        </tr>
    </tbody>
</table>";

but how to do this in delphi without using string concatenation, not so much for performance but for looking visually as nice as in c# instead of

Result :        = '<table width="100%" border="0" cellspacing="0" cellpadding="5" align="center" class="txsbody">';
Result : Result + '<tbody>';

Upvotes: 9

Views: 4051

Answers (1)

David Heffernan
David Heffernan

Reputation: 612954

How to do this in delphi without using string concatenation?

You cannot. There is no support for multi-line literals. Concatenation is the only option.

However, your Delphi code performs the concatenation at runtime. It's far better to do it at compile time. So instead of:

Result := 'foo';
Result := Result + 'bar';

write

Result := 'foo' +
          'bar';

Upvotes: 15

Related Questions