var
S,re_str:string;
i:integer;
begin
S:='http://www.sina.com/demo/demo.htm'
for i:=length(s) down to 1 do
if s='/' then
re_str:=copy(i,length(s)-i,s);//re_str就是所要的结果
end;
这种情况无非是最后由".htm"构成。
代码如下:
//已调试通过。
var
s: Pchar;
b: string;
begin
s := 'http://www.sina.com/demo/demo.htm';
b := string(StrRSCan(s, '/'));
Delete(b, 1, 1);
ShowMessage(String(b));
效率和资源最佳的方案:
function FileNameOnly(const FullName): String;
var
I, N, M: Integer;
begin
M:= Length(FullName);
for I:= 1 to M do begin
N:= M - I + 1;
if FullName[N] = '/' then begin
SetLength(Result, I-1);
Move(FullName[N+1], Result[1], I-1);
Break;
end;
end;
if N = 1 then Result:= FullName;
end;
function OperatStr(str: String): string;
var
CurrOperStr: string;
begin
CurrOperStr:='/'+str;
while pos('/',CurrOperStr)<>0 do
begin
CurrOperStr:= Copy(CurrOperStr,(pos('/',CurrOperStr)+1),Length(CurrOperStr));
Result:= CurrOperStr;
end;
end;
此法最好!
function GetUrlShortName(url: string):string;
var
i,j: integer;
begin
j:=0;
for i:= 1 to length(url) do if url='/' then j:=i;
delete(url,1,j);
result := url;
end;