function ChangeListNo(aListNo: String): String; var sListNo: String; begin sListNo := IntToStr(10000000000+StrToInt(aListNo)); Result := Copy(sListNo,2,10); end;
我以前写的一个函数,不但对数字串可以,对一般的串也可以。 {****************************************************************} { Written By BlazingFire 2002.9 } { The following function can make a string transfer to a new } { string which a little bigger than the old one. } {****************************************************************}function GetNextStr(OldStr:String):String; var i:integer; ChrOrd:Byte; begin Result:=' '+Trim(OldStr); for i:=Length(Result) DownTo 1 do begin ChrOrd:=Ord(Result[i]); if (ChrOrd in [Ord('a')..Ord('y')]) OR (ChrOrd in [Ord('0')..Ord('8')]) OR (ChrOrd in [Ord('A')..Ord('Y')]) then begin Result[i]:=Chr(ChrOrd+1); Result:=Trim(Result); exit; end else if Result[i]='z' then Result[i]:='a' else if Result[i]='Z' then Result[i]:='A' else if Result[i]='9' then Result[i]:='0' else begin Result[i]:='A'; Result:=Trim(Result); exit; end; end; end; eg: ShowMessage(GetNextStr('0001'));
function incString(s:string):string; var i,l:integer; s1:string; begin i:=strToInt(s); i:=i+1; s1:='00000'; l:=length(intToStr(i)); setLength(s1,5-l); result:=s1+intToStr(i); end;注意要 uses strUtils
摩托也送一个,比较有扩展性的~~~~ function incstr(s:string):string; var st:string; begin st:=inttostr(strtoint(s)+1); setlength(result,length(s)-length(st)); fillchar(pchar(result)^,length(result),'0'); result:=result+st; end;
function incString(s:string):string; var i:integer; s1:string; begin i:=length(s); s1 := inttostr(strtoint(s)+1); if i > length(s1) then begin setlength(result,i-length(s1)); fillchar(pchar(result)^,length(result),'0'); result:=result+s1; end else result:=s1; end; 我感觉这样比较容易控制你输入字符串的长度。不过只对数字有效。如果包括子母在内的话blazingfire(烈焰) 的方法还是不错的哦,
var
sListNo: String;
begin
sListNo := IntToStr(10000000000+StrToInt(aListNo));
Result := Copy(sListNo,2,10);
end;
{****************************************************************}
{ Written By BlazingFire 2002.9 }
{ The following function can make a string transfer to a new }
{ string which a little bigger than the old one. }
{****************************************************************}function GetNextStr(OldStr:String):String;
var
i:integer;
ChrOrd:Byte;
begin
Result:=' '+Trim(OldStr);
for i:=Length(Result) DownTo 1 do
begin
ChrOrd:=Ord(Result[i]);
if (ChrOrd in [Ord('a')..Ord('y')]) OR
(ChrOrd in [Ord('0')..Ord('8')]) OR
(ChrOrd in [Ord('A')..Ord('Y')]) then
begin
Result[i]:=Chr(ChrOrd+1);
Result:=Trim(Result);
exit;
end
else if Result[i]='z' then
Result[i]:='a'
else if Result[i]='Z' then
Result[i]:='A'
else if Result[i]='9' then
Result[i]:='0'
else
begin
Result[i]:='A';
Result:=Trim(Result);
exit;
end;
end;
end;
eg:
ShowMessage(GetNextStr('0001'));
var
i,l:integer;
s1:string;
begin
i:=strToInt(s);
i:=i+1;
s1:='00000';
l:=length(intToStr(i));
setLength(s1,5-l);
result:=s1+intToStr(i);
end;注意要 uses strUtils
function incstr(s:string):string;
var
st:string;
begin
st:=inttostr(strtoint(s)+1);
setlength(result,length(s)-length(st));
fillchar(pchar(result)^,length(result),'0');
result:=result+st;
end;
var
i:integer;
s1:string;
begin
i:=length(s);
s1 := inttostr(strtoint(s)+1);
if i > length(s1) then
begin
setlength(result,i-length(s1));
fillchar(pchar(result)^,length(result),'0');
result:=result+s1;
end
else
result:=s1;
end;
我感觉这样比较容易控制你输入字符串的长度。不过只对数字有效。如果包括子母在内的话blazingfire(烈焰) 的方法还是不错的哦,