# Substring Extraction Node

### Overview

The Substring Extraction Node extracts a portion of text from a source string using start and end position indices. This node is particularly useful for parsing structured text, extracting specific segments from larger content, or processing text data where you need only a particular section. It supports both positive and negative indexing with robust boundary handling.

**Usage cost:** 0 credit

### Configuration

#### Settings

**Source Configuration**

* **Source Text**\* (text area): The text from which to extract a substring
  * Use the variable insertion interface to reference text from other nodes
  * Supports multi-line text input
  * Variables are automatically interpolated during execution

**Position Configuration**

* **Start Index** (number): Starting position for substring extraction
  * Uses 0-based indexing (first character is position 0)
  * Negative values count from the end of the string
  * Default: `0` (beginning of string)
  * Examples:
    * `0`: Start from beginning
    * `5`: Start from 6th character
    * `-3`: Start 3 characters from end
* **End Index** (number): Ending position for substring extraction
  * Position is exclusive (character at end index is not included)
  * Use `-1` to extract to the end of the string
  * Negative values count from the end of the string
  * Default: `-1` (end of string)
  * Examples:
    * `-1`: Extract to end of string
    * `10`: Extract up to (but not including) 10th character
    * `-2`: Extract until 2 characters from end

### Output Ports

* `substring` (string): The extracted portion of the source text
  * Returns empty string if start index is greater than end index
  * Automatically handles out-of-bounds indices by clamping to valid ranges
  * Preserves original character encoding and formatting

### Best Practices

#### **Index Selection**

* Remember that indexing is 0-based (first character is at position 0)
* Use negative indices for extracting from the end of strings
* Test with sample data to verify correct positioning
* Consider string length variations when setting fixed indices

#### **Variable Integration**

* Use variables from previous nodes to make extraction dynamic
* Ensure source text variables are available when the node executes
* Test with different text lengths to verify robust extraction

#### **Boundary Handling**

* The node automatically handles out-of-bounds indices safely
* Start indices beyond string length will return empty results
* End indices beyond string length will extract to actual string end

#### **Common Patterns**

* **First N characters**: Start: `0`, End: `N`
* **Last N characters**: Start: `-N`, End: `-1`
* **Skip first N characters**: Start: `N`, End: `-1`
* **Remove last N characters**: Start: `0`, End: `-N`

### Common Issues

* **Empty results** - Check that start index is not greater than end index
* **Unexpected boundaries** - Verify indices are within expected string length ranges
* **Variable interpolation** - Ensure source text variables contain string data
* **Index confusion** - Remember that end index is exclusive (not included in result)


---

# 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://docs.waterflai.ai/studio/studio-builders/flow-components-nodes/substring-extraction-node.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.
