substring

Modified on Thu, 9 Jul at 10:49 AM

substring

TABLE OF CONTENTS

Fetch a substring of a string from a given position with a given length

Definition

string substring(string $text, integer $startIndex, int $substringLength)

Returns the substring of $text starting at $startIndex with length $substringLength.

Parameters

string $text

Text to select a substring of.

number $startIndex

The index of the original string where the first character of the substring is. Starts from zero.

int $substringlength

The length of the substring to be returned.

Returns

string

Substring of $text starting at $startIndex of length $substringLength.

Examples

Transformation
{
  a: substring('Hello, world!',`7`,`5`),
  b: substring('Hello, world!',`7`,`50`),
  c: substring('Hello, world!',`-7`,`5`),      // Error
  d: substring('Hello, world!',`0`,`0`),
  e: substring('Hello, world!',`0`,`true`),
  f: substring('Hello, world!',`0`,`null`),    // Error
  g: substring('',`0`,`10`),
  h: substring('',`1`,`10`),
  i: substring(`null`,`0`,`1`)
}
Result
{
  "a": "world",
  "b": "world!",
  "d": "",
  "e": "H",
  "g": "",
  "h": "",
  "i": null
}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article