for i:=0 to Length(aa)-1 do if aa[Length(aa)-i]='\' then begin aa:=Copy(aa,1,i); break; end;
function MyStr(sStr:String):String; var ii:Integer; str:String; begin str := sStr; result := ''; while POS('\',str) > 0 then begin Result := Result + Copy(str,1,POS('\',str)); str := Copy(str,POS('\',str)+1,Length(str)); end; end;
对不起,genphone_ru(票票) ,weizhi(行者) ,我是在application.initialize前作这些事,所以ExtractFileDir会报错的,555 用inbud(清风侠)的方法可以,如果要截到斜杠的话,你的程序应该是 for i:=0 to Length(aa)-1 do if aa[Length(aa)-i]='\' then begin aa:=Copy(aa,1,i+2); break; end; 不过还是谢谢你!
我一直在用以下函数,虽然笨但很有效. Feng是分隔符 aa:=c:\aaa\bbb\ccc.exe Gshow_title(aa,'\',1); Print ccc.exe Gshow_title(aa,'\',2); Print c:\aaa\bbb\ Gshow_title(aa,'\',3); Print c: Gshow_title(aa,'\',4); Print aaa\bbb\ccc.exefunction Gshow_title(str,feng:string;lei:integer):string; var i,k:integer; begin str:=trim(str); feng:=trim(feng); case lei of 1:begin//拆除单项,在后 k:=0; for i:=1 to length(str) do begin if str[i] = trim(feng) then k:=i+1; end;//for result:=copy(str,k,length(str)); end; 2:begin//拆除单项,在前 k:=0; for i:=1 to length(str) do begin if str[i] = trim(feng) then k:=i-1; end;//for result:=copy(str,1,k); end; 3:begin//拆除单项,在前 k:=0; for i:=1 to length(str) do begin if str[i] = trim(feng) then begin k:=i-1; break; end; end;//for result:=copy(str,1,k); end; 4:begin//拆除单项,在后 k:=0; for i:=1 to length(str) do begin if str[i] = trim(feng) then begin k:=i+1; break; end; end;//for result:=copy(str,k,length(str)); end; end; end;
呵呵,你在DPR文件的前面加入: program Project1;uses SysUtils, //加入此行就可以在其中的任何地方用 ExtractFilePath()等函数了
如,上例可写成
aa:=c:\aaa\bbb\ccc.exe
aa := ExtractFilePath(aa);
aa := ExtractFileDir('c:\aaa\bbb\ccc.exe')+'\';
delete--从字符串中删除指定的字符串
详细用法可察看delphi help
if aa[Length(aa)-i]='\' then
begin
aa:=Copy(aa,1,i);
break;
end;
var ii:Integer;
str:String;
begin
str := sStr;
result := '';
while POS('\',str) > 0 then
begin
Result := Result + Copy(str,1,POS('\',str));
str := Copy(str,POS('\',str)+1,Length(str));
end;
end;
用inbud(清风侠)的方法可以,如果要截到斜杠的话,你的程序应该是
for i:=0 to Length(aa)-1 do
if aa[Length(aa)-i]='\' then
begin
aa:=Copy(aa,1,i+2);
break;
end;
不过还是谢谢你!
不要搞得那么复杂
aa:=c:\aaa\bbb\ccc.exe
Gshow_title(aa,'\',1); Print ccc.exe
Gshow_title(aa,'\',2); Print c:\aaa\bbb\
Gshow_title(aa,'\',3); Print c:
Gshow_title(aa,'\',4); Print aaa\bbb\ccc.exefunction Gshow_title(str,feng:string;lei:integer):string;
var i,k:integer;
begin
str:=trim(str);
feng:=trim(feng);
case lei of
1:begin//拆除单项,在后
k:=0;
for i:=1 to length(str) do begin
if str[i] = trim(feng)
then k:=i+1;
end;//for
result:=copy(str,k,length(str));
end;
2:begin//拆除单项,在前
k:=0;
for i:=1 to length(str) do begin
if str[i] = trim(feng)
then k:=i-1;
end;//for
result:=copy(str,1,k);
end;
3:begin//拆除单项,在前
k:=0;
for i:=1 to length(str) do begin
if str[i] = trim(feng)
then begin
k:=i-1;
break;
end;
end;//for
result:=copy(str,1,k);
end;
4:begin//拆除单项,在后
k:=0;
for i:=1 to length(str) do begin
if str[i] = trim(feng)
then begin
k:=i+1;
break;
end;
end;//for
result:=copy(str,k,length(str));
end;
end;
end;
program Project1;uses
SysUtils, //加入此行就可以在其中的任何地方用
ExtractFilePath()等函数了