delphi 输出用空格对齐字符串的函数


本文整理自网络,侵删。

 { 函数 }
function ToAlignString(const str: string; len: Integer): string;
var
i,n: Integer;
s: string;
begin
if Abs(len) < Length(str) then Result := str;
n := (Abs(len) - Length(str)) * SizeOf(Char);
for i := 1 to Length(str) do if Ord(str[i]) < 256 then Inc(n);
if n > 0 then s := StringOfChar(' ', n);
if Len > 0 then Result := s + str else Result := str + s;
end;

{ 测试 }
procedure TForm1.FormCreate(Sender: TObject);
var
s1,s2: string;
begin
Memo1.Font.Name := '宋体';
Memo1.Font.Size := 9;
Memo1.Clear;

s1 := '中国abc';
s2 := '中国人民abc';
Memo1.Lines.Add(ToAlignString(s1, -10));
Memo1.Lines.Add(ToAlignString(s2, -10));
Memo1.Lines.Add(ToAlignString(s1, 10));
Memo1.Lines.Add(ToAlignString(s2, 10));
end;

相关阅读 >>

Delphi format格式化函数

Delphi ado 动态建立.mdb数据库,表

Delphi 查找字符串并删除该字符串

Delphi 中的字符串

Delphi 采用 tidhttp 访问 https 的网站,采用 tidtcpclient 访问 https 的网站

Delphi xe2 - 实现主窗口在任务栏上不显示

Delphi listbox自动获取列表框中的组件焦点

Delphi 强迫将半型英数字转换成全型英数字

Delphi和outputdebugstring

Delphi firedac 下的 sqlite [9] - 关于排序

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...