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

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

本文简介:选择自 qiubolecn 的 blog

      result := false;
      break;
    end;
  end;
end;

class function tstring.lastchar(avalue: string): char;
begin
  result := avalue[system.length(avalue)];
end;

class function tstring.left(avalue: string; alength: integer): string;
begin
  result := copy(avalue, 1, alength);
end;

class function tstring.right(avalue: string; alength: integer): string;
begin
  result := strutils.rightstr(avalue, alength);
end;

class function tstring.setstring(var s: string; buffer: pchar;
  len: integer): string;
begin
  system.setstring(s, buffer, len);
  result := s;
end;

class function tstring.stringin(avalue: string;
   avalues: array of string): boolean;
var
  i: integer;
begin
  result := false;
  for i := low(avalues) to high(avalues) do
  begin
    if uppercase(avalue) = uppercase(avalues[i]) then
    begin
      result := true;
      break;
    end;
  end;
end;

class function tstring.stringofchar(ch: char; count: integer): string;
begin
  result := system.stringofchar(ch, count);
end;

class function tstring.stringreplace(const s, oldpattern,
  newpattern: string; flags: treplaceflags): string;
begin
  result := sysutils.stringreplace(s, oldpattern, newpattern, flags);
end;

class function tstring.stringtocharset(avalue: string): tcharset;
var
  i: integer;
begin
  result := [];
  for i := 1 to length(avalue) do
  begin
    result := result + [avalue[i]];
  end;   
end;

function tstring.tolowercase: string;
begin
  result := lowercase(ftext);
end;

function tstring.touppercase: string;
begin
  result := uppercase(ftext);
end;

class function tstring.valueof(avalue: boolean): string;
begin
  if avalue then
    result := '是'
  else
    result := '否';
end;

class function tstring.valueof(avalue: string): boolean;
begin
  result := stringin(avalue, ['是', 'yes', 'ok']);
end;

class function tstring.getfirstword(avalue: string; var aword: string;
  aseparator: string): integer;
begin
  result := getfirstword(avalue, aword, stringtocharset(aseparator));
end;

class function tstring.getallword(avalue, aseparator: string): tstringlist;
var
  tmplist: tstringlist;
  tmpword: string;
begin
  tmplist := tstringlist.create;
  while length(avalue) > 0 do
  begin
    tmpword := '';
    delete(avalue, 1, getfirstword(avalue, tmpword, aseparator));
    if tmpword <> '' then
      tmplist.add(tmpword)
    else
      break;
  end;
  result := tmplist;
end;

class function tstring.updatesentence(aoldstring, aupdatesource,
  aupdatestring, asentenceseparator, awordseparator: string): string;
var
  tmpsentence: string;
  tmpword: string;
  tmpword1: string;
  i: integer;
  tmpresult: string;
begin
  //得到第一个句子
  tmpsentence := aoldstring;
  tmpresult := '';
  while length(tmpsentence) > 0 do
  begin
    i := getfirstword(tmpsentence, tmpword, asentenceseparator);
    tmpresult := tmpresult + left(tmpsentence, i - length(tmpword));
    delete(tmpsentence, 1, i);
    if tmpword <> '' then
    begin
      i := getfirstword(tmpword, tmpword1, awordseparator);
      tmpresult := tmpresult + left(tmpword, i - length(tmpword1));
      if comparestring(tmpword1, aupdatesource) then
      begin
        tmpresult := tmpresult + aupdatestring;
      end
      else
      begin
        tmpresult := tmpresult + tmpword;
      end;
    end;
  end;
  tmpresult := deleteprefix(tmpresult, [' ', ',']);
  tmpresult := deletesuffix(tmpresult, [' ', ',']);
  tmpresult := deleterepeat(tmpresult, ',', ' ');
  tmpresult := deleterepeat(tmpresult, ' ', ' ');

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

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

go top