有一个字符串是这样的
-B0208885B0252DDDD;
我想知道第二个B在这个字符串在的位置.谢谢

解决方案 »

  1.   

    Returns the index value of a substring.UnitStrUtilsCategorystring handling routinesDelphi syntax:function PosEx(const SubStr, S: string; Offset: Cardinal = 1): Integer;C++ syntax:extern PACKAGE int __fastcall PosEx(const AnsiString SubStr, const AnsiString S, unsigned Offset = 1);DescriptionPosEx returns the index of SubStr in S, beginning the search at Offset. If Offset is 1 (default), PosEx is equivalent to Pos.PosEx returns 0 if SubStr is not found, if Offset is greater than the length of S, or if Offset is less than 1.
      

  2.   

    这还不好办么
    FOR I:=LENGTH(S) DOWNTO 1 DO
      IF FINDCHAR=S[I] THEN BEGIN
        BREAK;//这里的I值就是最后一次出现的位置
      END;
      

  3.   


    function RPos(ASubStr: string; S: string): integer;
    var
      i,j: integer;
    begin
      result := -1;  if (length(ASubStr)>Length(S)) or (Length(S)=0) or (length(ASubStr)=0) then
        exit;  j := length(S)-length(ASubStr)+1;
      for i := j downto 1 do
      begin
        if copy(s,i,length(ASubStr))=ASubStr then
        begin
          result := i;
          exit;
        end;
      end;end;
      

  4.   


    uses StrUtils;{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    var
      s: string;
      i, n: Integer;
    begin
      s := '-B0208885B0252DDDD';
      i := 0;
      n := 0;
      repeat
        i := PosEx('B', s, i + 1);
        if i > 0 then
          n := i;
      until i < 1;
      ShowMessage(IntToStr(n));
    end;
      

  5.   

    凡事都要另类一点: ^_^uses StrUtils;const
      S : string = 'How do you do';
    begin
      ShowMessage(IntToStr(Pos('o',ReverseString(S))));
    end;
      

  6.   

    LastDelimiter('.', 'aaa.aaaa.ww')
      

  7.   

    不好意思,楼上楼上楼上我的代码不全面(算成倒数了),改为正着数:uses StrUtils;const
      S : string = 'How do you do';
    begin
      ShowMessage(IntToStr(Length(S)-Pos('a',ReverseString(S))+1));
    end;我楼上LastDelimiter就是很好的了。