README.md

December 4, 2022 ยท View on GitHub

Split string

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
ByMark van Renswoude
LevelIntermediate
User Rating5.0 (10 globes from 2 users)
CompatibilityDelphi 5, Delphi 4, Pre Delphi 4
CategoryString Manipulation
WorldDelphi
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;