# Get Sub String

This is a pre-built Action located under the **@Generic Element**. The functionality of this Action in Avo Assure is to extract a specific part of the input text based on the given index or range. The extracted portion is stored in a dynamic variable.

## **Syntax**&#x20;

**Input Value**: `<string>;<index OR range>`&#x20;

| Argument                                | Description                                                      |
| --------------------------------------- | ---------------------------------------------------------------- |
| <p>\<string ><br>(Required)</p>         | Provide the full string from which you want to extract a part.   |
| <p>\<index OR range ><br>(Required)</p> | Provide the position or range of characters you want to extract. |

{% hint style="info" %}
**Note**:&#x20;

* The index value starts from the 0<sup>th</sup> index till N<sup>th</sup>  index.
* **Index**: The extraction starts from the given index and continues until the end of the string.
* **Range**: Use the format StartIndex–EndIndex. The extraction starts from the StartIndex and stops just before the EndIndex. To include the last character, increase the EndIndex by **1** (total range+1).
  {% endhint %}

**Output Value**: `<Dynamic Varibale>;<Dynamic Variable>(Optional)`

| Argument                                  | Description                                                       |
| ----------------------------------------- | ----------------------------------------------------------------- |
| <p>\<Dynamic Variable><br>(Required)</p>  | This dynamic variable stores a specific portion of a string.      |
| <p>\<Dynamic Variable><br>(Optional) </p> | This dynamic variable stores the status as **True** or **False**. |

### **Example 1: Extracting a Substring from a String Using Index Value**

In this example, we explain how to extract a part of a string starting from a specific index in Input Value.

* **Action**: Get Sub String
* **Input Value**: Software Engineer;4
  * The first argument (**Software Engineer**) specifies the main string,&#x20;
  * The second argument (**4**) specifies the starting index from which the substring is extracted.
* **Output Value**: {Sub string}
  * The extracted substring (ware Engineer) is stored in this **{Sub string}** dynamic variable for further use.
  * If the second output variable is defined, it stores the action status with the following possible values:
    * **True**: If the substring is successfully extracted.
    * **False**: If the input value is empty or invalid.
* **Logical Explanation**: The **Get Sub String** action fetches the value from the **Input Value** column (**Software Engineer;4**) and extracts the substring starting from the specified index (4). For the given input, the resulting substring is (ware Engineer). The extracted substring is stored in the **{Sub string}** variable.

<figure><img src="https://2174257472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk8QZzXZMIJSStKAzDSTu%2Fuploads%2F6bIDYfHg4B7oLBqANxbZ%2Fimage.png?alt=media&#x26;token=3c36a077-e878-44b2-a7bf-a5a14cb9cb19" alt=""><figcaption></figcaption></figure>

### **Example 2:** Extracting a Substring **from a String** Using a Range Value

In this example, we explain how to extract a part of a string using a specific range in Input Value.

* **Action**: Get Sub String
* **Input Value**: Software Engineer;9–17
  * The first argument (**Software Engineer**) specifies the main string,&#x20;
  * The second argument (**9–17**) defines the range of characters to extract.
* **Output Value**: {Sub string}
  * The extracted substring (Engineer) is stored in this **{Sub string}** dynamic variable for further use.
  * If the second output variable is defined, it stores the action status with the following possible values:
    * **True**: If the substring is successfully extracted.
    * **False**: If the extraction fails due to an invalid range or input.
* **Logical Explanation**: The **Get Sub String** action fetches the value from the **Input Value** column (**Software Engineer;9-17**) and extracts the substring based on the specified range (9–17). For the given input string, the resulting substring is (Engineer). The extracted substring is stored in the **{Sub string}** variable.

<figure><img src="https://2174257472-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fk8QZzXZMIJSStKAzDSTu%2Fuploads%2FDBqoTYzNk7TWfkBpddr1%2Fimage.png?alt=media&#x26;token=f885e420-f2ff-4718-8b6b-f71deb4f7cb3" alt=""><figcaption></figcaption></figure>

#### **Knowledge Bites:**&#x20;

Here are some examples of different string scenarios:

| String               | Input Value                                                                                                                                                | Result                                                                                                         |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| Text Strings         | <p><strong>index:</strong> Automation;4</p><p>                         <strong>OR</strong></p><p><strong>range:</strong> Automation;3-10 </p>              | <p><strong>index:</strong> mation</p><p>    <strong>OR</strong></p><p><strong>range:</strong> omation</p>      |
| Numeric Strings      | <p><strong>index:</strong> 12345678;4 </p><p>                         <strong>OR</strong></p><p><strong>range:</strong> 12345678;3-10</p>                  | <p><strong>index:</strong> 5678</p><p>    <strong>OR</strong> </p><p><strong>range:</strong> 45678</p>         |
| Special Character    | <p><strong>index:</strong> <abc@domain.com>;4 </p><p>                         <strong>OR</strong></p><p><strong>range:</strong> <abc@domain.com>;3-10 </p> | <p><strong>index:</strong> domain.com</p><p>    <strong>OR</strong> </p><p><strong>range:</strong> @domain</p> |
| Alphanumeric strings | <p><strong>index:</strong> ID2025;4  </p><p>                         <strong>OR</strong></p><p><strong>range:</strong> ID2025;3-6</p>                      | <p><strong>index:</strong> 25</p><p> <strong>OR</strong> </p><p><strong>range:</strong> 025</p>                |
