var a:string; i,count:integer; begin count:=0; a:='AB"DE"GE"UKM"VOP'; for i:=1 to length(a) do if a[i]='"'then inc(count); if odd(count) then ShowMessage('奇') else ShowMessage('偶'); end;
function myProc(s: string): integer; var str: string; i: integer; begin Result := 0; if Pos('V', s)<0 then exit; str := Copy(s, 1, Pos('V', s)-1); for i:=1 to length(str) do if str[i]='"'then Inc(Result); end;myProc返回值就是V前面"的个数
应用:procedure TForm1.Button1Click(Sender: TObject); function myProc(s, t: string): boolean; var str: string; i, j: integer; begin j := 0; if Pos(t, s)>0 then begin str := Copy(s, 1, Pos(t, s)-1); for i:=1 to length(str) do if str[i]='"'then Inc(j); end; Result := false; if (j mod 2)=1 then Result := true; end; begin if myProc('AB"DE"GE"UKM"VOP', 'V') then ShowMessage('是奇数个"') else ShowMessage('不是奇数个"'); end;
i,count:integer;
begin
count:=0;
a:='AB"DE"GE"UKM"VOP';
for i:=1 to length(a) do
if a[i]='"'then inc(count);
if odd(count) then ShowMessage('奇') else ShowMessage('偶');
end;
var
str: string;
i: integer;
begin
Result := 0;
if Pos('V', s)<0 then exit;
str := Copy(s, 1, Pos('V', s)-1);
for i:=1 to length(str) do
if str[i]='"'then Inc(Result);
end;myProc返回值就是V前面"的个数
function myProc(s, t: string): boolean;
var
str: string;
i, j: integer;
begin
j := 0;
if Pos(t, s)>0 then
begin
str := Copy(s, 1, Pos(t, s)-1);
for i:=1 to length(str) do
if str[i]='"'then Inc(j);
end;
Result := false;
if (j mod 2)=1 then Result := true;
end;
begin
if myProc('AB"DE"GE"UKM"VOP', 'V') then
ShowMessage('是奇数个"')
else
ShowMessage('不是奇数个"');
end;