Memo1的处理

Frewin 2008-05-23 02:52:01
有一TStringList ,数据如下 a b c e f g
现在需要将Memo1填写为 a b
c e
e f
g
...全文
160 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
blazingfire 2008-05-23
  • 打赏
  • 举报
回复

procedure TForm1.Button1Click(Sender: TObject);
var
StrList: TStringList;
i: integer;
Line: string;
begin
StrList := TStringList.Create;
try
StrList.Add('aabc');
StrList.Add('b2');
StrList.Add('c33');
StrList.Add('ddbb');
StrList.Add('edd');
StrList.Add('fa');
StrList.Add('gbb');
StrList.Add('StrList.');
Memo1.Lines.Clear;

i := 0;
while i < StrList.Count do
begin
Line := StrList[i];
if Length(Line) < 6 then
Line := Line + StringOfChar(' ', 6 - Length(Line));//保证第一个长度为6
if i + 1 < StrList.Count then
Line := Line + StrList[i + 1];
Memo1.Lines.Add(Line);
Inc(i, 2);
end;
finally
StrList.Free;
end;
end;
Frewin 2008-05-23
  • 打赏
  • 举报
回复
只需要限制第一列全部是6个字符就行了。
gzmhero 2008-05-23
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 Frewin 的回复:]
接上题:
为了统一宽度,怎样将字符设置为限长(6个字符),不够的补空格
如:
abcf abc
edf edg
在第二行edf后补一空格,使得宽度一样
abcf abc
edf edg
[/Quote]

需求模糊,每行的长度是多少?
踢踏 2008-05-23
  • 打赏
  • 举报
回复
使用等宽字体,如宋体等,
Format('%-6s%s',['abcf','abc']);
Format('%-6s%s',['edf','edg']);
gzmhero 2008-05-23
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 Frewin 的回复:]
请问TStringList可以排序吗?
[/Quote]

可以。
Frewin 2008-05-23
  • 打赏
  • 举报
回复
请问TStringList可以排序吗?
Frewin 2008-05-23
  • 打赏
  • 举报
回复
接上题:
为了统一宽度,怎样将字符设置为限长(6个字符),不够的补空格
如:
abcf abc
edf edg
在第二行edf后补一空格,使得宽度一样
abcf abc
edf edg

blazingfire 2008-05-23
  • 打赏
  • 举报
回复
var
List: TStringList;
begin
List := TStringList.Create;
....
List.Assign(Memo.Lines);
....
end;
Frewin 2008-05-23
  • 打赏
  • 举报
回复

请问楼上,怎样将一个Memo 赋值给TStringList ?
leihao2041 2008-05-23
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 gzmhero 的回复:]
strs:TStringList;

for i:=0 to strs.Count/2-1 do
Memo1.Lines.Add(strs.Strings[i*2]+' '+strs.Strings[i*2+1]);
[/Quote]

日志-病毒-网络-操作系统-安全-c#-asp.net-java-delphi-sql-oracle学习资源
在这里可以找找http://japee.com.cn/jew/bbs.aspx
gzmhero 2008-05-23
  • 打赏
  • 举报
回复
上面的代码有bug,当strs是奇数数量会出错。


procedure TForm1.Button1Click(Sender: TObject);
var
strs:TStringList;
i:integer;
begin
strs:=TStringList.Create;
strs.Add('a');
strs.Add('b');
strs.Add('c');
strs.Add('d');
strs.Add('e');
strs.Add('f');
strs.Add('g');

for i:=0 to (strs.Count div 2)-1 do
Memo1.Lines.Add(strs.Strings[i*2]+' '+strs.Strings[i*2+1]);

if (strs.Count mod 2)<>0 then
Memo1.Lines.Add(strs.Strings[strs.count-1]);

strs.Free;
end;

gzmhero 2008-05-23
  • 打赏
  • 举报
回复
strs:TStringList;

for i:=0 to strs.Count/2-1 do
Memo1.Lines.Add(strs.Strings[i*2]+' '+strs.Strings[i*2+1]);

16,749

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧