AI摘要
文章介绍了Delphi 7中新增的idstring单元中的SplitString函数,该函数用于字符串拆分处理。由于Delphi 6中没有这个单元,作者将函数原形提取出来,使其在D6下也可以使用。文章提供了SplitString函数的详细代码和实现过程。
文章介绍了Delphi 7中新增的idstr
在delphi7中增加了idstring单元,里边有一个splitstring函数,对于字符串拆分处理非常方便,但是在delphi6中没有这个单元,我把这个函数原形提出来,在D6下也可以直接使用。
procedure SplitString(const AStr, AToken: String; var VLeft, VRight: String);
var
i: Integer;
LLocalStr: String;
begin
{ It is possible that VLeft or VRight may be the same variable as AStr. So we copy it first }
LLocalStr := AStr;
i := Pos(AToken, LLocalStr);
if i = 0 then
begin
VLeft := LLocalStr;
VRight := '';
end
else
begin
VLeft := Copy(LLocalStr, 1, i - 1);
VRight := Copy(LLocalStr, i + Length(AToken), Length(LLocalStr));
end;
end;