一个字串,如:
aaaa,bbb,ccc,ddd,aaaaa
取最后一个逗号的位置 ?有没现成的function?

解决方案 »

  1.   

    function lastDH(str: String): Integer;
    var
      i: Integer
    begin
      Result := -1;
      for i := 0 to length(str)
        if str[i] = ',' then
          Result := i;
    end;我没有在delphi下测试,你试试看行不?
      

  2.   

    function lastDH(str: String): Integer;
    var
      i: Integer
    begin
      Result := -1;
      for i := 0 to length(str)-1
        if str[i] = ',' then
          Result := i+1;
    end;这样ok!
      

  3.   

    自己写一个
    function last(s:string,c:char):int//求s中最后一个c的位置
    var i:int
    begin
      result:= -1;
      for i := 1 to s.length do
      begin
        if s[i] = c then
          result := i;
      end;
    end;调用last('aaaa,bbb,ccc,ddd,aaaaa', ',')
      

  4.   

    好像没有,要自己写的吧var
      s: string
      i,j: Integer
    begin
      j:=0;
      for i := 0 to length(s) do
      begin
        if s[i] = ',' then j:=i;
      end;
      

  5.   

    对,这样就行!少了个do
    function lastDH(str: String): Integer;
    var
      i: Integer
    begin
      Result := -1;
      for i := 0 to length(str) do
        if str[i] = ',' then
          Result := i;
    end;
      

  6.   

    function lastchar(str: String): Integer;
    var
      i: Integer;
    begin
      Result := 0;
      for i := length(str) downto 1
        if str[i] = ',' then 
        begin
          Result := i;
          break;
        end;
    end;
      

  7.   

    我试过了可以,不过需要修改的地方是:function lastDH(str: String): Integer;
    var
      i: Integer
    begin
      Result := -1;
      for i := 0 to length(str) do(你的do忘了)
        if str[i] = ',' then
          Result := i;
    end;
      

  8.   

    function lastDH(str: String): Integer;
    var
      i: Integer
    begin
      Result := 0;
      for i := length(str) downto 1 
        if str[i] = ',' then
        begin 
           Result := i;
           break;
        end;
    end;
      

  9.   

    function lastDH(str:string):integer;
    var
      str2:array[0..50] of char;
      i:integer;
    begin
      result:=-1;
      strcopy(str2,str);
      for i:=0 to length(str) do
        if str2[i]=',' then
           result:=i;
    end;
      

  10.   

    Delphi有这个函数,帮助文档如下:Returns the byte index in S of the last character that matches any character in the Delimiters AnsiString.UnitSysUtilsCategorystring handling routinesfunction LastDelimiter(const Delimiters, S: string): Integer;DescriptionCall LastDelimiter to locate the last delimiter in S. For example, the lineMyIndex := LastDelimiter('\.:','c:\filename.ext');sets MyIndex to 12.When working with multi-byte character sets (MBCS), S may contain double byte characters, but the delimiters listed in the Delimeters parameter must all be single byte non-null characters.
      

  11.   

    Caption := IntToStr(LastDelimiter(',', 'aaaa,bbb,ccc,ddd,aaaaa'));
      

  12.   

    function PosExt(SubStr,S:String;RDirection:Boolean=False;RepeatCount:Integer=1):Integer;
    var TempSubStr,TempS:String;
        i,j:Integer;
    begin
      TempS:=S;
      TempSubStr:=SubStr;
      //从右边查询,将字符倒序
      if RDirection then begin
        TempS:='';
        for i:=Length(S) downto 1 do
          TempS:=TempS+Copy(S,i,1);
        TempSubStr:='';
        for i:=Length(SubStr) downto 1 do
          TempSubStr:=TempSubStr+Copy(SubStr,i,1);
      end;
      j:=0;
      for i:=1 to Length(TempS) do begin
        if Copy(TempS,i,Length(TempSubStr))=TempSubStr then
          j:=j+1;
        if j=RepeatCount then
          Break;
      end;
      if j=RepeatCount then
        if RDirection then
          Result:=Length(TempS)-(i+Length(TempSubStr)-1)+1
        else
          Result:=i
      else
        Result:=0;
    end;
      

  13.   

    aaaa,bbb,ccc,ddd,aaaaa
    取最后一个逗号的位置 ?有没现成的function?
    var
      str,str1 :string;
      commapos:integer; //逗号的位置
    begin
      str :='aaaa,bbb,ccc,ddd,aaaaa;         
      while pos(',', str) <> 0 do
      str1 :=Copy(str, Pos(',', str) + 1, Length(str));//最后一个逗号后的字符串
      commapos := length(str)-length(str1);没有测试过,不知道对不对:)
      
                            
      

  14.   

    把我的删了吧,别人比我写的好多了,keke~~不好意思
      

  15.   

    function lastDH(str: String): Integer;
    var
      i: Integer
    begin
      Result := -1;
      for i := 0 to length(str)
        if str[i] = ',' then
          Result := i;
    end;