Skip to content

String Substr

The string::substr function extracts a substring from a string, starting at a specified position and optionally taking a certain number of characters.

Syntax

string::substr(<string>, <start>, <length>)

Parameters

  • string: The input string to extract from.
  • start: The zero-based index at which to begin extraction.
  • length: The optional number of characters to extract. If not provided, the substring continues to the end of the string.

Returns

  • String: The extracted substring.

Example

Try it out below!
string::substr("hello world", 6, 5)

This function is useful for isolating parts of a string based on position.