delphi去除两端换行符
时间: 2023-08-09 10:11:21 浏览: 73
在 Delphi 中,可以使用 `Trim` 函数去除字符串两端的空白字符,包括换行符。但是如果你只想去除两端的换行符,可以使用以下代码:
```delphi
function TrimNewLine(const S: string): string;
begin
Result := S;
while (Length(Result) > 0) and (Result[1] in [#10, #13]) do
Delete(Result, 1, 1);
while (Length(Result) > 0) and (Result[Length(Result)] in [#10, #13]) do
Delete(Result, Length(Result), 1);
end;
```
这个函数会先循环删除字符串开头的换行符,然后再循环删除字符串结尾的换行符。调用这个函数,可以得到去除了两端换行符的字符串。
相关问题
delphi 回车换行符
在 Delphi 中,回车换行符可以通过 `#13#10` 来表示。其中,`#13` 表示回车符,`#10` 表示换行符。你可以在字符串中使用这两个字符的组合来表示回车换行。例如:
```delphi
var
myString: string;
begin
myString := 'This is line 1.' + #13#10 + 'This is line 2.';
ShowMessage(myString);
end;
```
上面的代码将会在消息框中显示两行文字,第一行是 "This is line 1.",第二行是 "This is line 2.",它们之间通过回车换行符进行分隔。
delphi 回车换行符 byte
在 Delphi 中,回车换行符可以使用以下两种方式表示:
1. 使用 13 和 10 两个 byte 类型变量表示,其中 13 表示回车符,10 表示换行符。例如:
```
var
CR, LF: Byte;
begin
CR := 13;
LF := 10;
Memo1.Lines.Add('第一行' + Chr(CR) + Chr(LF) + '第二行');
end;
```
2. 使用 sLineBreak[1] 和 sLineBreak[2] 两个 byte 类型变量表示,它会根据当前操作系统的不同自动填充正确的回车换行符。例如:
```
Memo1.Lines.Add('第一行' + Chr(sLineBreak[1]) + Chr(sLineBreak[2]) + '第二行');
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)