大家讨论一下分割字符串的效率问题,高人请进……
最近在项目中遇到分割字符串的问题,因为数据量比较大,大概有5万多条,每条字符串用特定的字符隔开。
开始用copy来分割,发现效率奇低,后来又用Pchar配合汇编分割,效率有所提高,但还是不是很如意。
不知道各位大侠有何高见……
附上用copy的方法(用pchar配合汇编的方法因为大部分是公司牛人写的,不便公开,请见谅)
function SplitString(const source, ch: string): TResultArray;
var
temp: string;
i: integer;
begin
temp := source;
i := pos(ch, source);
while i <> 0 do
begin
SetLength(Result, Length(Result) + 1);
Result[Length(Result) - 1] := copy(temp, 0, i - 1);
delete(temp, 1, i);
i := pos(ch, temp);
end;
SetLength(Result, Length(Result) + 1);
Result[Length(Result)-1] := Temp;
end;