请问,如何判断一字符串中,在指定字符前面的"(双引号)数,是否是奇数?比如,字符串:
A:='AB"DE"GE"UKM"VOP'请问,如何判断字符 V 的前面的"(双引号)数量是否是奇数?高手帮看看,谢了.

解决方案 »

  1.   

    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;
      

  2.   

    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前面"的个数
      

  3.   

    应用: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;