Delphi Tip - 디렉토리 문자열 분리

Programming/Delphi 2010.04.04 06:31 Posted by 파란크리스마스


uses
  StrUtils;

procedure TForm1.Button1Click(Sender: TObject);
var
  tmpDirStr : String;
  offset : integer;

  function GetFindStr(SubFindStr : String; var offset : integer):string;
  var
    offsetOld, offset2 : integer;
  begin
    Result := '';

    offset2 := 0;
    if SubFindStr[offset] = '/' then
      inc(offset2);

    offsetOld := offset;
    offset := PosEx('/', SubFindStr, offset + offset2);

    if offset>0 then begin
      Result := MidStr(SubFindStr, offsetOld + offset2, offset-offsetOld-offset2);
    end;
  end;

begin
  tmpDirStr := Edit1.Text;

  if (tmpDirStr[Length(tmpDirStr)]<>'/') then
    tmpDirStr := tmpDirStr + '/';

  offset := 1;

  while (offset > 0) do begin
    Memo1.Lines.Add(GetFindStr(tmpDirStr, offset));
  end;
end;

신고


 

티스토리 툴바