Choose where you’d like to start

subText

Overview

The subText function takes source_text, start_index, and end_index as arguments. It returns a piece of text containing characters between the specified indices (including the start_index and excluding the end_index).

Note:

  • Index starts from 0
  • The start_index and/or end_index should not exceed the length of the source_text. If it exceeds, an error will be encountered during execution.
  • The end_index must be greater than or equal to the start_index, failing which an error will be encountered during runtime.
  • If start_index and end_index are the same, then the function will return an empty text.
  • You can use the subString or mid function to perform the same operation as the subText function.

Return Type

  • TEXT

Syntax

<variable> = <source_text>.subText(<start_index>, [<end_index>]);

(OR)

<variable> = subText(<source_text>, <start_index>, [<end_index>]);

where,

ParameterData typeDescription
<variable>TEXTVariable which contains the returned text.
<source_text>TEXTThe source of text on which subText function is effected.
<start_index>NUMBER

The index starting from which the characters in the source text will be returned.

<end_index>

 (optional)

NUMBER

The index until which the characters in the source text will be returned. If omitted, the rest of the text (from the start index) will be returned.

If a negative value is specified, this param will be ignored and rest of the text (from the start index) will be returned.

Examples

 1) product_name="Zoho Deluge";
 result = product_name.subText(5,-12); // Negative End Index
 info  result; // Negative end index is ignored and the text is returned from index 5
 2) product_name="Zoho Deluge";
 result = product_name.subText(0,4);
 info  result; // Returns Zoho (does not include the end_index)
 3) product_name="Zoho Deluge";
 result = product_name.subText(6,4);
 info  result; // throws error as end index is lesser than start index

Get Started Now

Execute