README.md
December 4, 2022 ยท View on GitHub
Description
This code simply splits a string into pieces using any delimiter and returns an array. Enjoy!It seems PSC has messed up my code, to view a nicely formatted and color coded version of this code go to http://x2software.net/viewarticle.php?id=5
More Info
| Submitted On | |
| By | Mark van Renswoude |
| Level | Intermediate |
| User Rating | 5.0 (10 globes from 2 users) |
| Compatibility | Delphi 5, Delphi 4, Pre Delphi 4 |
| Category | String Manipulation |
| World | Delphi |
| Archive File |
Source Code
type
TSplitArray = array of String;
function Split(const Source, Delimiter: String): TSplitArray;
var
iCount: Integer;
iPos: Integer;
iLength: Integer;
sTemp: String;
aSplit: TSplitArray;
begin
sTemp := Source;
iCount := 0;
iLength := Length(Delimiter) - 1;
repeat
iPos := Pos(Delimiter, sTemp);
if iPos = 0 then
break
else begin
Inc(iCount);
SetLength(aSplit, iCount);
aSplit[iCount - 1] := Copy(sTemp, 1, iPos - 1);
Delete(sTemp, 1, iPos + iLength);
end;
until False;
if Length(sTemp) > 0 then begin
Inc(iCount);
SetLength(aSplit, iCount);
aSplit[iCount - 1] := sTemp;
end;
Result := aSplit;
end;