Field-Map Scripting

4.1.2.11 GetFieldFromString

GetFieldFromString function


Prototype:

function GetFieldFromString(const Data: string; const Index: integer; const FieldDelimiter: char): string;

Description:

Returns a field with specified index from input string. Indices are counted from 0. The fields in the string are separated by given parameter FieldDelimiter.

Syntax:

GetFieldFromString(Data, Index, FieldDelimiter);


Part

Description


Data

source string containing several fields


Index

zero based index of field to be returned


FieldDelimiter

a character used to delimit the fields in the input string

Return value:

A portion of the input string which corresponds to the requested field or empty string if the field with given index does not exist in the string.


Example:


var

  v: variant;

  area, TotArea: double;

  i, n, idCuttingArea, idSubCompartment, nCompartment, nSubCompartment: integer;

  s, f, vdm: string;

  c: char;


begin

// ...

  idCuttingArea := CuttingAreas['ID']; { ID of the active cutting area }

// ...

  Mensuration.First;

whilenot Mensuration.EOFdo

begin

    s := Mensuration['SubCompartmentName'];

    n := GetFieldCountFromString(s, ',');

if n > 1 then

      c := ','

else

begin

      n := GetFieldCountFromString(s, '.');

      c := '.';

end;

    area := 0;

for i := 0 to n - 1 do

begin{ goes through the list of the captured intersections }

{ finds out the number of the captured intersection }

      f := GetFieldFromString(s, i, c);

{ its ID is needed }

      nSubCompartment := StrToInt(f); { the number of the captured interssection }

      idSubCompartment := SubCompartments.GetAttributeValue('ID',

        format('CompartmentName = %d AND SubCompartmentName = %d', [nCompartment, nSubCompartment]));

      v := Project.GetPolygonIntersectArea_m2('CuttingAreas', idCuttingArea, 'SubCompartments', idSubCompartment);

if v <> null then

        area := area + double(v);

{ a list of intersections included in Mensuration }

      vdm := vdm + IntToStr(idSubCompartment) + '|';

end;

// ...

    Mensuration.Next;

end;

end.



See also:

Format; LZero; Delete; Trim; TrimLeft; TrimRight; SameText; StringReplace; DeFormat1-10; GetFieldCountFromString;GetFieldFromString; IndexOfField; SortNumericSequence