string 要在 TMemoBox 中显示的字符串内的换行符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4510707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Newline Inside a String To Be Shown At a TMemoBox
提问by Nathan Campos
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:
我正在构建一个String
被调用的FullMemo
,它将显示在 a TMemoBox
,但问题是我正在尝试像这样制作换行符:
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?
我得到的是txtFirstMemo
字符的内容\n
,而不是换行符,以及txtDetails
. 我应该怎么做才能使换行符工作?
回答by
The solution is to use #13#10 or better as Sertac suggested sLineBreak.
解决方案是使用 #13#10 或更好的 Sertac 建议sLineBreak。
FullMemo := txtFistMemo.Text + #13#10 + txtDetails.Text;
FullMemo := txtFistMemo.Text + sLineBreak + txtDetails.Text;
回答by Jens Mühlenhoff
A more platform independent solution would be TStringList
.
更独立于平台的解决方案是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('');
回答by Bharat
Use
用
FullMemo := txtFistMemo.Text + #13#10 + txtDetails.Text
回答by himself
You don't make newlines like this, you use symbol #13:
您不会像这样创建换行符,而是使用符号 #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.
#13 是 CR,#10 是 LF,有时只使用 CR 就足够了,有时(例如在编写文本文件时)使用 #13#10。
回答by Migrate2Lazarus see my profile
You can declare something like this:
你可以这样声明:
const
CRLF = #13#10;
LBRK = CRLF+ CRLF;
in a common unit and use it in all your programs. It will be really handy.
在一个公共单元中并在您的所有程序中使用它。真的会很方便。