求出下一个发票号,如FP001的下一个为FP002,FP 001 X的下一个为FP 002 X,FP 001 XN 002的下一个号码为FP 002 XN 002
总是取出第一个数字并加一,但是不足的位数要补零
函数如下:
function GetNextFp(curNo:string):string;
var
iNum:LongInt;
sPre,sLast,sTemp,sNum:string;
MyRegExp,Matches:OleVariant;
begin
MyRegExp :=CreateOleObject('VBScript.RegExp');
MyRegExp.Global :=True;
MyRegExp.Pattern :='(.[^\d]*)(\d+)(.*)';
Result :=curNo;
try
if MyRegExp.Test(curNo) then
begin
Matches :=MyRegExp.Execute(curNo);
sTemp :=Matches.Items[0].SubMatches[1];
iNum :=StrToInt(sTemp)+1;
sNum :=StringOfChar('0',Length(sTemp)-Length(IntToStr(iNum)))+IntToStr(iNum);
sPre :=Matches.Item[0].SubMatches[0];
sLast :=Matches.Item[0].SubMatches[2];
Result :=Format('%s%s%s',[sPre,sNum,sLast]);
end;
except
end;
end;
测试
Showmessage(GetNextFp('NTF0090PD71038KPU'));
Showmessage(GetNextFp('NTF0090'));
Showmessage(GetNextFp('0090'));
Showmessage(GetNextFp('TTT'));
Showmessage(GetNextFp('NT 0090 X 001'));