在 C# 中,您可以使用多行文字字符串来生成跨越源代码中的物理换行符的字符串,例如
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 中做到这一点而不使用字符串连接,与其说是为了性能,不如说是为了在视觉上看起来像在 c# 中一样漂亮,而不是
Result : = '<table width="100%" border="0" cellspacing="0" cellpadding="5" align="center" class="txsbody">';
Result : Result + '<tbody>';
最佳答案
How to do this in delphi without using string concatenation?
你不能。不支持多行文字。连接是唯一的选择。
但是,您的 Delphi 代码在运行时执行串联。在编译时执行此操作要好得多。所以代替:
Result := 'foo';
Result := Result + 'bar';
写
Result := 'foo' +
'bar';
关于string - 如何在 Delphi/Pascal 中执行多行逐字字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34726466/