Delphi沒(méi)有自己的字符串分割函數(shù),所以只能程序員自己寫(xiě)了,網(wǎng)上搜了好多但是真正好用的沒(méi)有幾個(gè)。
下面這個(gè)是我在網(wǎng)上找到修改后了的,個(gè)人感覺(jué)算法不錯(cuò),所以就貼了上來(lái)。
function SplitString(Source, Deli: string ): TStringList;stdcall;
var
EndOfCurrentString: byte;
StringList:TStringList;
begin
StringList:=TStringList.Create;
while Pos(Deli, Source)>0 do
begin
EndOfCurrentString := Pos(Deli, Source);
StringList.add(Copy(Source, 1, EndOfCurrentString - 1));
Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) - EndOfCurrentString);
end;
Result := StringList;
StringList.Add(source);
end;
下面這個(gè)是我在網(wǎng)上找到修改后了的,個(gè)人感覺(jué)算法不錯(cuò),所以就貼了上來(lái)。
function SplitString(Source, Deli: string ): TStringList;stdcall;
var
EndOfCurrentString: byte;
StringList:TStringList;
begin
StringList:=TStringList.Create;
while Pos(Deli, Source)>0 do
begin
EndOfCurrentString := Pos(Deli, Source);
StringList.add(Copy(Source, 1, EndOfCurrentString - 1));
Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) - EndOfCurrentString);
end;
Result := StringList;
StringList.Add(source);
end;