string - 如何在 Delphi/Pascal 中执行多行逐字字符串

标签 string delphi

在 C# 中,您可以使用多行文字字符串来生成跨越源代码中的物理换行符的字符串,例如

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>";

但如何在 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/

相关文章:

连接值时发生 Javascript 错误

java - 将 int 转换为 Java 中的二进制字符串表示形式?

delphi - zlib目录(保存路径)

delphi - 子表中具有替代链接字段的主/子

delphi - ARC : is there a memory leak in TNetEncoding. 获取Base64Encoding?

在不知道缓冲区大小的情况下将整数转换为字符串

javascript - JS : cache string array at client for entire session

c - 为什么我不能将两个字符串组合在一起?

class - 如何在类声明中使用预定义变量

exception - 更改 Lazarus 中的异常消息