比如有字符串  s := 'c:\asd\asd\aaa.txt'  怎样可以得到 s 的 substring := 'aaa.txt'  
请给出上例的具体代码 谢谢~~~~~~~~~~

解决方案 »

  1.   

    GetSubStr('c:\asd\asd\aaa.txt','\',4)='aaa.txt'function GetSubStr(s_str, d_str: string; po: integer): string; //s_str大字符串,d_str分隔符,po位置
    var
      i, j, k: integer;
    begin
      result := '';
      if po < 1 then
        exit;
      s_str := trim(s_str) + d_str;
      i := 0;
      while 1 = 1 do
      begin
        if pos(d_str, s_str) > 0 then
        begin
          j := pos(d_str, s_str) + length(d_str);
          k := length(s_str) - (j - 1);
          i := i + 1;
          if i = po then
          begin
            j := pos(d_str, s_str);
            result := copy(s_str, 1, j - 1);
            break;
          end;
          s_str := copy(s_str, j, k);
        end
        else
          break;
      end;
    end;
      

  2.   

    你是不是想从s里取出'aaa.txt'  是吧?
    那可以用substring :=stringreplace(s,'aaa.txt' ,'aaa.txt' [fignorecase]);
      

  3.   

    var
      a:integer;
    --用a:=function Pos(Substr: string; S: string): Integer;循环判断s中是否有\,
    --如果有令s为s:=copy(s,a,len(s)-a),一直到字符串中没有'\'为止.
      

  4.   

    同意tiexinliu(铁心刘) :
    用copy(s,a,len(s)-a),
      

  5.   

    s := 'c:\asd\asd\aaa.txt';
    substring := ExtractFileName(s);
      

  6.   

    你这个问题就是用楼上所说的 extractfilename('c:\asd\asd\aaa.txt');
    如果取文件路径用extractfilepath('c:\asd\asd\aaa.txt' );