Home

XtrNN:

Procedure XtrNn(All,Sep: STRING; VAR Item, Left: STRING);
VAR
	a: INTEGER;
BEGIN
a:=Pos(sep,All);
IF a=0 THEN BEGIN
	Item:=All;
	Left:='';
	END
ELSE BEGIN
	IF a=1 THEN Item:='' ELSE Item:=Copy(All,1,a-1);
	Delete(All,1,a+Len(Sep)-1); 
	Left:=ALL;
	END;
END;
I use this routine to parse data that has been strung into text. It will Extract text ("Item") from a larger string "ALL" using the text "Sep" as the delimiter and returns the Extracted text "Item" and the Remainder of the text string in variable "Left".
So you can take something like a Text list such as "Label,Color,Size,Type" and parse it out to variables.
Seperators can be one or multiple characters.
Procedure Xtest;
VAR
n: INTEGER;
Item: ARRAY [1..4] OF STRING;
Alist: STRING;

{Insert XtrNn Procedure here}

BEGIN
n:=0;
Alist:='Label,Color,Size,Type';
WHILE Alist<>'' DO BEGIN {repeats loop as long as there is text left in Alist}
	n:=n+1;
	XtrNn(Alist,',',Item[n],Alist); {Etract next item from list}
	AlrtDialog(Concat('Item ',n,'=',Item[n]));
	END;
END;
Run(Xtest);