字符串内的换行符显示在 TMemoBox 上

发布于 2024-10-08 22:46:20 字数 306 浏览 8 评论 0原文

我正在构建一个名为 FullMemoString ,它将显示在 TMemoBox 上,但问题是我正在尝试创建换行符像这样:

FullMemo := txtFistMemo.Text + '\n' + txtDetails.Text

我得到的是 txtFirstMemo 字符 \n 的内容,而不是换行符,以及 txtDetails 的内容。我应该怎么做才能使换行工作?

I'm building a String called FullMemo, that would be displayed at a TMemoBox, but the problem is that I'm trying to make newlines like this:

FullMemo := txtFistMemo.Text + '\n' + txtDetails.Text

What I got is the content of txtFirstMemo the character \n, not a newline, and the content of txtDetails. What I should do to make the newline work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

无法言说的痛 2024-10-15 22:46:21

解决方案是使用 #13#10 或更好的 Sertac 建议 sLineBreak

FullMemo := txtFistMemo.Text + #13#10 + txtDetails.Text;
FullMemo := txtFistMemo.Text + sLineBreak + txtDetails.Text;

The solution is to use #13#10 or better as Sertac suggested sLineBreak.

FullMemo := txtFistMemo.Text + #13#10 + txtDetails.Text;
FullMemo := txtFistMemo.Text + sLineBreak + txtDetails.Text;
痴骨ら 2024-10-15 22:46:21

一个更加独立于平台的解决方案是TStringList

var
  Strings: TStrings;
begin
  Strings := TStringList.Create;
  try
    Strings.Assign(txtFirstMemo.Lines); // Assuming you use a TMemo
    Strings.AddStrings(txtDetails.Lines);
    FullMemo := Strings.Text;
  finally
    Strings.Free;
  end;
end;

要添加空换行符,您可以使用:

Strings.Add('');

A more platform independent solution would be TStringList.

var
  Strings: TStrings;
begin
  Strings := TStringList.Create;
  try
    Strings.Assign(txtFirstMemo.Lines); // Assuming you use a TMemo
    Strings.AddStrings(txtDetails.Lines);
    FullMemo := Strings.Text;
  finally
    Strings.Free;
  end;
end;

To Add an empty newline you can use:

Strings.Add('');
才能让你更想念 2024-10-15 22:46:21

使用

FullMemo := txtFistMemo.Text + #13#10 + txtDetails.Text

Use

FullMemo := txtFistMemo.Text + #13#10 + txtDetails.Text
殊姿 2024-10-15 22:46:21

您可以在公共单元中声明如下内容

const 
 CRLF = #13#10; //or name it 'Enter' if you want
 LBRK = CRLF+ CRLF;

并在所有程序中使用它。这真的会很方便。现在,20 年后,我已经在数千个地方使用了 CRLF!

FullMemo := txtFistMemo.Text + CRLF + txtDetails.Text

重要
在 Windows 中,正确的输入格式是 CRLF,而不仅仅是 CR 或 LF,正如其他人建议的那样。
例如,如果您的文件没有正确的输入(CRLF),Delphi IDe(这是一个 Windows 应用程序)将会对您非常生气:
Delphi XE - 所有蓝点都移动一排队

You can declare something like this:

const 
 CRLF = #13#10; //or name it 'Enter' if you want
 LBRK = CRLF+ CRLF;

in a common unit and use it in all your programs. It will be really handy. Now, after 20 years, I have CRLF used in thousands of places!

FullMemo := txtFistMemo.Text + CRLF + txtDetails.Text

IMPORTANT
In Windows, the correct format for enters is CRLF not just CR or just LF as others sugges there.
For example Delphi IDe (which is a Windows app) will be really mad at you if your files do not have proper enters (CRLF):
Delphi XE - All blue dots are shifted with one line up

风月客 2024-10-15 22:46:21

你不要像这样换行,你使用符号#13:

FullMemo := txtFistMemo.Text + #13 + txtDetails.Text
    + Chr(13) + 'some more text'#13.

#13是CR,#10是LF,有时只使用CR就足够了,有时(例如在编写文本文件时)使用#13#10。

You don't make newlines like this, you use symbol #13:

FullMemo := txtFistMemo.Text + #13 + txtDetails.Text
    + Chr(13) + 'some more text'#13.

#13 is CR, #10 is LF, sometimes it's enough to use just CR, sometimes (when writing text files for instance) use #13#10.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文