Slice Text
Uncontrolled node
Overview
The Slice Text node extracts a portion of a text string based on specified start and end character positions. It uses zero-based indexing, meaning the first character is at position 0. The node returns the substring starting from the specified start index up to, but not including, the specified end index.
This is useful for extracting specific portions of text, such as trimming headers, removing footers, or isolating specific sections of a larger text block.
Inputs
| Input | Type | Description | Default |
|---|---|---|---|
| Text | Text | The source text string to slice. | - |
| Start | Number | The zero-based index position to begin the slice (inclusive). If omitted or invalid, defaults to 0. | 0 |
| End | Number | The zero-based index position to end the slice (exclusive). If omitted or invalid, defaults to the length of the text. | Length of text |
Outputs
| Output | Type | Description |
|---|---|---|
| Output | Text | Contains the sliced substring from the start index up to (but not including) the end index. |
Runtime Behavior and Defaults
- Uncontrolled Node: This node runs automatically when its inputs change and does not require an event trigger.
- Index Handling: Both start and end values are converted to integers (floored) if decimal numbers are provided.
- Default Start: If the start input is missing, not a number, or empty, it defaults to 0 (the beginning of the string).
- Default End: If the end input is missing, not a number, or empty, it defaults to the length of the input text (the end of the string).
- Invalid Text: If the text input is not a string, the node returns an empty string.
- Slice Logic: The node uses JavaScript's
String.prototype.slice()method, which means:- If start is greater than end, an empty string is returned.
- If start is negative, it is treated as 0.
- If end is greater than the string length, it is treated as the string length.
Example
Scenario: Extracting a specific portion from a document header.
Inputs:
- Text:
"CONFIDENTIAL - Project Alpha Report - Page 1" - Start:
17(skipping "CONFIDENTIAL - ") - End:
35(stopping before " - Page 1")
Output:
- Output:
"Project Alpha Report"
Workflow Tip: Combine this node with the Find In Text node to dynamically determine start and end positions based on specific patterns or markers within the text.