Привет всем!!!
Такой вот вопрос меня волнует:
1. есть метод Split
function Split (const S: String; Separator:
String; MyStringList: TStringList = nil) : TStringList;
var
Start: integer;
wantCount : Integer;
begin
Result := TStringList.Create();
if Assigned(MyStringList) then
Result.AddStrings(MyStringList);
Start := 0;
while Start <= Length(S) do
Result.Add(GetNextToken(S, Separator, Start)) ;
end;
function GetNextToken (S: string; Separator:
String; var StartPos: integer): String;
var
Index: integer;
begin
Result := '';
if StartPos > length(S) then
Exit;
S := Copy(S, StartPos + 1, length(S));
Index := pos(Separator, S);
if Index = 0 then
Index := length(S)
else
Index := Index - 1;
Result := Copy(S, 0, Index);
StartPos := StartPos + Index + 1;
end;
2. следующие:
var
curFile : TstringList;
curLine : TStirngList;
curIndex : array[0..10] of integer;
begin
curFile := TStirngList.Create();
try
curFile.LoadeFromFile('1.txt');
for i = 0 to curFile.Count - 1 do
begin
curLine := Split(curFile[i], ';');
try
for j = 0 to Params.Count - 1 do
begin
case j of
0, 1, 3 :
if curIndex[j] < curLine.Count - 1 then
Params[j].AsString := curLine[curIndex[j]];
...
end;
end;
finally
FreeAndNil(curLine);
end;
end;
finally
FreeAndNil(curFile);
end;
end;
Не будет ли быстрей переделать так чтоб использовать метод Copy?
допустим так:
function GetDataToIndex(inStr : String; index :
integer; delimiter : string) : string;
var
i : integer;
begin
Result := '';
while (inStr <> '') and
(pos(delimiter, inStr) > 0) do
begin
Result := copy(inStr, 0, pos(delimiter, inStr) - 1);
if i = index then
exit;
inStr := copy(inStr, pos(delimiter, inStr) + 1, Length(inStr));
end;
end;
и естественно использовать вот так:
var
curFile : TstringList;
curIndex : array[0..10] of integer;
begin
curFile := TStirngList.Create();
try
curFile.LoadeFromFile('1.txt');
for i = 0 to curFile.Count - 1 do
begin
for j = 0 to Params.Count - 1 do
begin
case j of
0, 1, 3 :
if curIndex[j] < curLine.Count - 1 then
Params[j].AsString :=
GetDataToIndex(curFile[i], curIndex[j], ';');
...
end;
end;
end;
finally
FreeAndNil(curFile);
end;
end;
____________________________________________________________________________________
Жизнь хитрая штука - как только все карты на руках — она решает сыграть с тобой в шахматы!