0 Members and 2 Guests are viewing this topic.
function Explode(Source: string; const Delimiter: string): array of string;var Position, DelLength, ResLength: integer;begin DelLength := Length(Delimiter); Source := Source + Delimiter; repeat Position := Pos(Delimiter, Source); SetArrayLength(Result, ResLength + 1); Result[ResLength] := Copy(Source, 1, Position - 1); ResLength := ResLength + 1; Delete(Source, 1, Position + DelLength - 1); until (Position = 0); SetArrayLength(Result, ResLength - 1);end;
function Explode(Source: string; const Delimiter: string): array of string;var Position, DelLength, ResLength, CurResLength: integer;begin DelLength := Length(Delimiter); Source := Source + Delimiter; CurResLength := 1; SetArrayLength(Result, 1); repeat Position := Pos(Delimiter, Source); if (CurResLength = ResLength) then begin CurResLength := 2 * CurResLength; SetArrayLength(Result, CurResLength); end; Result[ResLength] := Copy(Source, 1, Position - 1); ResLength := ResLength + 1; Delete(Source, 1, Position + DelLength - 1); until (Position = 0); SetArrayLength(Result, ResLength - 1);end;
SetArrayLength(Result, ResLength + 1);Result[ResLength] := Copy(Source, 1, Position - 1);ResLength := ResLength + 1;Delete(Source, 1, Position + DelLength - 1);
... other codes...for i := 0 to (GetArrayLength(X)-1) do begin WriteConsole(ID, X[i], RGB(255,215,0));end;...other codes...
[*] first line[*] second line[*] third line[*] <nothing>
function Explode(Source: string; const Delimiter: string): array of string;var Position, DelLength, ResLength: integer;begin DelLength := Length(Delimiter); Source := Source + Delimiter; Position := Pos(Delimiter, Source); <<<<<<<<<<<<<<<<<<<<<<<< repeat SetArrayLength(Result, ResLength + 1); Result[ResLength] := Copy(Source, 1, Position - 1); ResLength := ResLength + 1; Delete(Source, 1, Position + DelLength - 1); Position := Pos(Delimiter, Source); <<<<<<<<<<<<<<<<<<<<<<<< until (Position = 0); SetArrayLength(Result, ResLength - 1);end;
SetArrayLength(Result, ResLength - 2);
SetArrayLength(Result, ResLength - 1);
Never had such problems with this function, maybe you have a delimiter at the end of the exploded text and that's where the empty element comes from
doesnt readfile add #13#10 in the end of the result string?
Quote from: dnmr on June 01, 2011, 04:00:51 pmdoesnt readfile add #13#10 in the end of the result string?I don't know but it probably does because otherwise Explode wouldn't be able to get the last line.