# convert-text-to-datatable

## Description

<mark style="color:purple;">`convert-text-to-datatable`</mark> *adaptor converts* [*DSV text*](https://en.wikipedia.org/wiki/Delimiter-separated_values) *into a datatable using specified separators to denote the split for columns and new rows.*

The default character used as column delimiter is `,` (comma), this can be changed by setting the `delimiter` input. The default character used as row delimiter is (LF), this can be changed by setting the `newline` input.

## Inputs

**`csv`**\
Type: `text`\
Required: Yes\
The text to be converted to datatable.

**`delimiter`**\
Type: `text`\
Required: No\
Character used as column delimiter. If unspecified, defaults to "," (comma).

**`newline`**\
Type: `text`\
Required: No\
Character used as line separator. If unspecified, defaults to  (newline).

**`trim`**\
Type: `boolean`\
Required: No\
Specifies whether to ignore whitespace characters immediately around the separator. If unspecified, defaults to `True`.

**`columns`**\
Type: `list`\
Required: No\
List of column names to be added. If unspecified, first row of the file will be used as column names.

## Outputs

**`data`**\
Type: `datatable`\
A datatable.

## Examples

### Example 1: Default behaviour.

#### Inputs:

`text`:

```
Year,Make,Model
1997,Ford,E350
2000,Mercury,Cougar
```

#### Outputs:

`data`:

| Year | Make    | Model  |
| ---- | ------- | ------ |
| 1997 | Ford    | E350   |
| 2000 | Mercury | Cougar |

-> Converted CSV text to a datatable.

### Example 2: Convert text with vertical bar as value separator and semicolon as row separator.

#### Inputs:

`text`:

```
Year|Make|Model;1997|Ford|E350;2000|Mercury|Cougar;
```

`delimiter`: `|` ([vertical bar](https://en.wikipedia.org/wiki/Vertical_bar))

`newline`: `;` (semicolon)

#### Outputs:

* `data`:

  | Year | Make    | Model  |
  | ---- | ------- | ------ |
  | 1997 | Ford    | E350   |
  | 2000 | Mercury | Cougar |

-> Converted text with vertical bar as a value separator and semicolon as a row separator to a datatable.

### Example 3: Text without header line.

#### Inputs:

`text`:

```
1997,Ford,E350
2000,Mercury,Cougar
```

`columns`:

* Column1
* Column2
* Column3

#### Outputs:

`data`:

| Column1 | Column2 | Column3 |
| ------- | ------- | ------- |
| 1997    | Ford    | E350    |
| 2000    | Mercury | Cougar  |

-> Converted text without header line to a datatable.

## Use Cases

* Add small reference dataset into a workflow rather than adding a file or user-provided input.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cgps.gitbook.io/data-flo/reference-guide/convert-text-to-datatable.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
