didi.04-9-10 教师节
function splitex(const str {需要拆分的文章}, delimiters {拆分关键字,回车.?!等}: string): tstringlist;
var
ss: widestring;
i, st: integer;
function isdelimiter(const delimiters, c: string): boolean;
begin //判断是否为拆分关键字
result := strscan(pchar(delimiters), c[1]) <> nil;
end;
begin
result := tstringlist.create;
with result do
begin
clear; sorted := true; duplicates := dupignore;
end;
if length(str) < 1 then exit;
ss := str; //双字符支持,纯英文可以去掉
st := -1;
for i := 1 to length(ss) do
if isdelimiter(delimiters, ss[i]) then
if st <> -1 then
begin
result.add(trim(copy(ss, st, i - st)));
st := -1;
end
else
if st = -1 then st := i;
if st <> -1 then result.add(copy(ss, st, length(str)));
end;
//操作演示
with splitex(memo1.text, ',,. ?! ' + #13#10) do
try
savetofile('c:\temp_demo.txt');
finally
free;
end;
原帖 http://community.csdn.net/expert/topic/3357/3357097.xml?temp=.9228937