VOOZH about

URL: https://www.geeksforgeeks.org/typescript/typescript-string-substring-method/

⇱ TypeScript String substring() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

TypeScript String substring() Method

Last Updated : 15 Jul, 2025

The substring() is an inbuilt function in TypeScript that returns the subset of a String object. It takes two parameters: indexA (starting index) and optional indexB (ending index, non-inclusive). It returns the portion of the string between these indices.

Syntax

string.substring(indexA, [indexB]) 

Parameter: This method accepts two parameters as mentioned above and described below: 

  • indexA : This parameter is the integer between 0 and one less than the length of the string.
  • indexB : This parameter is the integer between 0 and the length of the string.

Return Value: This method returns the subset of a String object. 

Below example illustrate the String substring() method in TypeScript.

Example 1: Basic Usage

In this example we extracts a substring from str, starting at index 0 and ending at index 5.

Output:

Geeks

Example 2: Extracting Substrings with Different Indices

In this example, we demonstrate the use of substring() with different indices to extract various parts of the string.

Output:

Geeks
Geeks
s - Best P
G
Comment
Article Tags:
Article Tags:

Explore