result := tmpresult;
end;
class function tstring.deleterepeat(aoldstring: string; adeletestring,
arepeat: char): string;
var
i: integer;
tmpfind1: boolean;
begin
tmpfind1 := false;
for i := length(aoldstring) downto 1 do
begin
if tmpfind1 then
begin
if aoldstring[i] = adeletestring then
delete(aoldstring, i, 1)
else
begin
if aoldstring[i] = arepeat then
continue;
tmpfind1 := aoldstring[i] = adeletestring;
end;
end
else
begin
if adeletestring <> arepeat then
if aoldstring[i] = arepeat then
continue;
tmpfind1 := aoldstring[i] = adeletestring
end;
end;
result := aoldstring;
end;
class function tstring.deletesuffix(avalue: string;
fixedstring: tcharset): string;
begin
while system.length(avalue) > 0 do
begin
if avalue[system.length(avalue)] in fixedstring then
delete(avalue, system.length(avalue), 1)
else
break;
end;
result := avalue;
end;
class procedure tstring.getallword(avalue, aseparator: string;
astringlist: tstrings);
var
tmpword: string;
begin
if astringlist = nil then
astringlist := tstringlist.create;
while length(avalue) > 0 do
begin
tmpword := '';
delete(avalue, 1, getfirstword(avalue, tmpword, aseparator));
if tmpword <> '' then
astringlist.add(tmpword)
else
break;
end;
end;
class function tstring.ifthen(aexpression: boolean; atrue,
afalse: string): string;
begin
if aexpression then
result := atrue
else
result := afalse;
end;
class function tstring.absolutetorelate(aabsolute,
acurrent: string): string;
var
tmpsimilarstring: string;
aoldfile: string;
i: integer;
tmppos: integer;
begin
//转换后形成 ..\..\a.ini;
//如果不在同一个驱动器上,则直接返回绝对路径.
if extractfiledrive(aabsolute) <> extractfiledrive(acurrent) then
result := aabsolute
else
begin
tmpsimilarstring := '';
aoldfile := aabsolute;
aabsolute := extractfilepath(aabsolute);
tmppos := similarposition(aabsolute, acurrent);
delete(aoldfile, 1, tmppos - 1);
delete(acurrent, 1, tmppos - 1);
for i := 0 to getcharnum(acurrent, '\') -1 do
begin
tmpsimilarstring := tmpsimilarstring + '..\';
end;
result := tmpsimilarstring + aoldfile;
end;
end;
class function tstring.relatetoabsolute(arelate, acurrent: string): string;
var
tmpsimilarstring: string;
tmprootcount: integer;
i: integer;
begin
if length(arelate) > 2 then
begin
if arelate[2] = ':' then
begin
result := arelate;
exit;
end;
end;
tmpsimilarstring := '';
tmprootcount := 0;
while true do
begin
if leftstr(arelate, 3) = '..\' then
begin
inc(tmprootcount);
delete(arelate, 1, 3);
end
else
break;
end;
tmpsimilarstring := reversestring(extractfilepath(acurrent));
for i := 0 to tmprootcount do
begin
delete(tmpsimilarstring, 1, pos('\', tmpsimilarstring));
end;
result := reversestring(tmpsimilarstring) + arelate;