注册 登录
编程论坛 Delphi论坛

0001+1怎么才能等于0002啊?

zhansong333 发布于 2006-04-23 00:10, 807 次点击
label1.caption:=0009;
执行语句: label1.caption:=inttostr(strtoint(label1.caption)+1);
之后,label.caption就为 '10' 了;
怎样才能让它为 '0010' 啊 ;谢谢!
6 回复
#2
volte2006-04-23 09:55
使用一个前补齐得函数就可以实现了
#3
xu20002006-04-23 12:11

向二楼的请教,补齐函数是什么?

#4
kekele0072006-04-23 12:23
label1.caption:='00'+inttostr(strtoint(label1.caption)+1);
#5
zhansong3332006-04-23 13:04
问四楼的:
如果是0001 + 1 到0002
不得这样写:
label1.caption:='000'+inttostr(strtoint(label1.caption)+1);

如果有上千个题目 , 这样写是不是很复杂啊,

二楼的请教,补齐函数是什么啊
#6
xu20002006-04-23 13:53

我到是有一个关于这方面的自定义函数,楼主可以参考一下。
//自动增加编码号
function autoaddbm(s:string):string;
var
i,j:integer;
tmp:string;
begin
try
j:=strtoint(s);
j:=j+1;
tmp:=inttostr(j);
if length(s)-length(tmp)>0 then
for i:=length(tmp) to length(s)- length(tmp) do
begin
tmp:='0'+tmp;
autoaddbm:=tmp;
end
else if length(s)=length(tmp) then
autoaddbm:=tmp
else
exit;
except
autoaddbm:='no auto add';
end;
end;

#7
ysp_19842006-04-24 10:03
用format函数
function Format(const Format: string; const Args: array of const): string; $[SysUtils.pas
Format('x=%.5d', [12]); //'x=00012' //前面补充0
1