ExtractValue Function
Retrieves the P'th Value in a String containing several values separated by given Separator which defaults to a semicolon.

Unit
QESBPCSConvert

Declaration
Function ExtractValue(const ValuesStr: string; var P: Integer; const Separator: Char = ';'): string;

Description
Thus 'Mon;Tue;Wed' has 'Mon' as the 1st string, 'Tue' as the 2nd string, etc. If you request a Value exceeding the number of values present then an Empty String is returned.

Parameters
ValuesStr String containing Values separated by given Separator.
Separator Character used to separate values, defaults to ';'.

Category
Extra String Handling Routines

Implementation

function ExtractValue (const ValuesStr: string; var P: Integer;
     const Separator: Char = ';'): string;
var
     I: Integer;
begin
     if P < 1 then
          P := 1;

     I := P;
     // Find next ';' or end of string
     while (I <= Length (ValuesStr)) and (ValuesStr [I] <> Separator) do
          Inc (I);

     // Grab the Trimmed Value
     Result := Trim (Copy (ValuesStr, P, I - P));

     // If at a ';' then jump to the next character
     if (I <= Length (ValuesStr)) and (ValuesStr [I] = Separator) then
          Inc (I);

     P := I;
End;


HTML generated by Time2HELP
http://www.time2help.com