编写了两段小程序,Split是用来分割字符串的,把字符串分割成了一个TStringList对象;Splice是用来合并字符串的,把一个StringList对象合并为一个字符串。
注:只因为不知道TStringList的Delimiter和DelimitedText才编写的。
procedure Split(const Source, Delimiter: string;
var RetVal: TStringList);
var
bPos, ePos, len: integer;
begin
bPos := 1;
ePos := PosEx(Delimiter, Source);
if not Assigned(RetVal) then
RetVal := TStringList.Create;
while ePos >= bPos do
begin
RetVal.Add(MidStr(Source, bPos, ePos - bPos));
bPos := ePos + 1;
ePos := PosEx(Delimiter, Source, bPos);
end;
len := Length(Source);
if bPos < len then
RetVal.Add(MidStr(Source, bPos, len - bPos + 1));
end;
procedure Splice(Const Source: TStrings;
const Delimiter: string; var RetVal: string);
var
i, imax, len: integer;
begin
len := Length(Delimiter);
imax := Source.Count - 1;
RetVal := '';
for i := 0 to imax do
RetVal := Delimiter + Source[i];
if Length(RetVal) > len then
Delete(RetVal, 1, len);
end;
你可以使用这个链接引用该篇文章 http://publishblog.blogchina.com/blog/tb.b?diaryID=2265076