IDtFieldSplitter.Split

Syntax

Split(FieldIndex: Integer; Delimiters: String; [MaxFields: Integer = 10;] [MaxRows: Integer = 100]): Boolean;

Parameters

FieldIndex. Index of the field that must be split.

Delimiters. Splitter.

MaxFields. Maximum number of fields resulted after splitting. The specified number must not be less than two.

MaxRows. Maximum number of rows that are used for analysis on splitting.

Description

The Split method splits a field by its contents according to the specified splitter.

Comments

The ability to split a field into several ones is available only for string fields. Splitting is executed by means of analysis of field values whether they contain repeated splitters. If exactly two characters are passed in Delimiters, they are considered paired splitters: the first character is an opening splitter, the second character is a closing splitter. Paired splitters can be equal. For example, to split the field with the data: "«value» «1»", specify "«»" in Delimiters. As a result, two fields with the values enclosed within "«»" are created.

When splitting a field, the system goes through data provider records that is why after executing the method the cursor may stay in the last record.

After splitting is completed, the output fields are available in the Fields collection. Names of created fields are formed by adding the number of created field to the split field name. Enumeration starts form one.

Example

Executing the example requires the file D:\Work\Data.xlsx. The first column contains some string data.

Add links to the Dt, Metabase system assemblies.

Sub UserProc;
Var
    ExcelProviderEx: IDtExcelProviderEx;
    FieldSplitter: IDtFieldSplitter;
    Fields: IDtFieldDefinitions;
    Field: IDtFieldDefinition;
    FieldsNames: String;
Begin
    
// Open data provider
    ExcelProviderEx := New DtExcelProviderEx.Create;
    ExcelProviderEx.File := 
"D:\Work\Data.xlsx";
    ExcelProviderEx.Sheet := 
"Sheet1";
    ExcelProviderEx.HasHeader := 
True;
    ExcelProviderEx.HeaderRow := 
0;
    ExcelProviderEx.Format := 
"XLSX";
    ExcelProviderEx.DataRow := 
1;
    ExcelProviderEx.Metabase := MetabaseClass.Active;
    ExcelProviderEx.Open;
    
// Split field
    FieldSplitter := ExcelProviderEx As IDtFieldSplitter;
    FieldSplitter.Split(
0",");
    
// Obtained information about fields
    Fields := ExcelProviderEx.Fields;
    Debug.WriteLine(
"Number of fields: " + Fields.Count.ToString);
    FieldsNames := 
"Field names: ";
    
// Form string with field names
    For Each Field In Fields Do
        FieldsNames := FieldsNames + Field.Name + 
"; "
    
End For;
    Debug.WriteLine(FieldsNames);
    ExcelProviderEx.Close;
End Sub UserProc;

Executing the example opens the specified file. An attempt to split the first field with the "," splitter is made. Information about output fields is displayed in the development environment console.

See also:

IDtFieldSplitter