我对DELPHI写的几个基类型[5]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 qiubolecn 的 blog

  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;

本文关键:我对DELPHI写的几个基类型
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top