将String转化为TStringList

转至:http://www.codesky.net/article/200308/1394.html

function StringToWords(const sString, Token:string): TStringList;
var
sTmp:string;
iPos: Integer;
Toklen: Integer;
begin
Toklen := Length(Token);
Result := TStringList.Create;
sTmp := sString;
iPos := Pos(Token, sTmp);
while iPos <> 0 do
begin
Result.Add(Copy(sTmp, 1, iPos - 1));
Delete(sTmp, 1, iPos - 1 + Toklen);
iPos := Pos(Token, sTmp);
end;
Result.Add(sTmp);
end;





使用案例:


var
iField:integer;
lStrList :TStringList;
begin
lStrList := TStringList.Create;
with ClientDataSet1 do
for iField := 0 to FieldCount -1 do
begin
lStrList := StringToWords(Fields[iField].FieldName,';');
end;
end;


你可能感兴趣的:(将String转化为TStringList)