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, ' ', ' ');