{调用时,外部的stringlist不要create,使用strlist =SplitString()来调用,调用者自己负责
把stringlist free掉 } function SplitString(const Source, ch: string): TStringList; var temp, s: string; i, len: Integer; begin //如果是空自符串则返回空列表 Result := TStringList.Create(); if length(Source) * length(ch) = 0 then exit; temp := Source; i := pos(ch, Source); if i = 0 then exit; len := length(ch); while i <> 0 do begin s := copy(temp, 0, i - 1); Result.add(s); {从位置1开始删除,删除i+len-1个} Delete(temp, 1, i + len - 1); i := pos(ch, temp); end; Result.add(temp); end; {------------------------------------------------------------------------------} |
|