如歌判断该字符串从后向前数第一个字符的的位数???比如:E3052EAS00325   程序返回的结果为第八位,后面的都为数字,没有无效字符出现

解决方案 »

  1.   

    var
        i:integer;
        str:string;
        a:integer;
    begin
        str:='E3052EAS00325';
        for i:=Length(str) downto 1 do
        begin
            if not TryStrToInt(str[i],a) then
            begin
                Result:=i;
                break;
            end;
        end;
    end;
      

  2.   

      s := 'E3052EAS00325';
      for i := length(s) downto 1 do
      begin
        if s[i] in ['0'..'9'] then
          continue
        else
        begin
          showmessage(inttostr(i));
          break;
        end;
      end;
      

  3.   

    function GetCharIndex(const S: String): Integer;
    begin
      for Result := Length(S) downto 0 do
      begin
        if S[Result] in ['0'..'9'] then
          Continue
        else if S[Result] in ['a'..'z','A'..'Z'] then
          Exit
        else
          Break;
      end;
      Result := 0;
    end;procedure TForm1.FormCreate(Sender: TObject);
    begin
      ShowMessage(IntToStr(GetCharIndex('E3052EAS00325')));
    end;