Friday, September 5, 2025
HomeLanguagesJavascriptTypeScript | String substring() Method

TypeScript | String substring() Method

The substring() is an inbuilt function in TypeScript which is used to return the subset of a String object.

 Syntax: 

string.substring(indexA, [indexB]) 

Parameter: This method accepts two parameter 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 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:  

JavaScript




<script>
    // Original strings
    var str = "Geeksforneveropen - Best Platform";
  
    // use of String substring() Method
    var newstr = str.substring(0,5)
  
    console.log(newstr);
</script>


Output: 

Geeks

Example 2: 

JavaScript




<script>
    // Original strings
    var str = "Geeksforneveropen - Best Platform";
  
    // use of String substring() Method
    var newstr = str.substring(0,5)
    console.log(newstr);
  
    newstr = str.substring(-2,5)
    console.log(newstr);
  
    newstr = str.substring(12,22)
    console.log(newstr);
  
    newstr = str.substring(0,1)
    console.log(newstr);
</script>


Output: 

Geeks
Geeks
s - Best P
G
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11861 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS