如何在Delphi / Pascal中执行多行逐字字符串 [英] How do I do a multiple line verbatim string in Delphi/Pascal
问题描述
在c#中,您可以使用多行文字字符串来跨越源代码中的物理中断字符串,例如
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"> </td>
<td width="85%" class="ttxb"><b>COMPANY NAME</b></td>
</tr>
</tbody>
</table>";
但是如何在delphi中执行此操作,而不使用字符串连接,而不是为了性能而不是视觉上看结果:='< table width =100%border =0的单元格空格,而不是
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>';
推荐答案
在delphi中不使用字符串连接?
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.
但是,您的Delphi代码在运行时执行连接。在编译时做得更好。所以而不是:
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';
写
Result := 'foo' +
'bar';
这篇关于如何在Delphi / Pascal中执行多行逐字字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!