我用了两个小时写了下面的一段,没考虑汉字和下划线,你试试看可有用,献丑了
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
s1, s2: string;
i, len, carry: integer;
function IsNumber(alpha: char):boolean;
var
ti: integer;
begin
ti := ord(alpha) - ord('0');
if (ti >= 0) and (ti <=9) then
Result := True //是数字
else
Result := False
//不是数字
end;
function number(c: char):integer;
begin
result := ord(c) - ord('0');
end;
begin
s1 := trim(edit1.Text)
//edit1中是输入车牌号
s2 := s1;
len := length(s1);
carry := 1;
for i := len downto 1 do
begin
if IsNumber(s1) then //是数字
begin
if Number(s1)+ carry = 10 then
begin
s2 := '0';
carry := 1;
end
else
begin
s2 := chr( ord(s1) + carry )
break;
end;
end
else //是字母
begin
if s1='Z' then
begin
if (i=len) or (carry=1) then
begin
s2 := '0';
carry := 1;
end
else
begin
s2 := s1;
break;
end
end
else
begin
s2 := chr(ord(s1) + carry);
break;
end;
end;
end;
edit2.text := s2
//edit2 -- 输出车牌号
end;
end.