JavaScript String Substring() Method - W3Schools
Maybe your like
Examples
Extract a substring from text:
let text = "Hello world!"; let result = text.substring(1, 4); Try it Yourself »Start from position 2:
let result = text.substring(2); Try it Yourself »More examples below.
Description
The substring() method extracts characters, between two indices (positions), from a string, and returns the substring.
The substring() method extracts characters from start to end (exclusive).
The substring() method does not change the original string.
If start is greater than end, arguments are swapped: (4, 1) = (1, 4).
Start or end values less than 0, are treated as 0.
See Also:
The split() Method
The slice() Method
The substr() Method
Syntax
string.substring(start, end)Parameters
| Parameter | Description |
| start | Required. Start position. First character is at index 0. |
| end | Optional.End position (up to, but not including).If omitted: the rest of the string. |
Return Value
| Type | Description |
| A string | A string containing the extracted characters. |
More Examples
If start is greater than end, parameters are swapped: let result = text.substring(4, 1); Try it Yourself »
If "start" is less than 0, it will start from index 0:
let result = text.substring(-3); Try it Yourself »Only the first:
let result = text.substring(0, 1); Try it Yourself »Only the last:
let result = text.substring(text.length - 1); Try it Yourself »Related Pages
JavaScript Strings
JavaScript String Methods
JavaScript String Search
Browser Support
substring() is an ECMAScript1 (JavaScript 1997) feature.
It is supported in all browsers:
| Chrome | Edge | Firefox | Safari | Opera |
Tag » What Is Substring In C#
-
Substring In C# - C# Corner
-
C# | Substring() Method - GeeksforGeeks
-
String.Substring Method (System) | Microsoft Learn
-
C# String Substring() (With Examples) - Programiz
-
C# Substring() Method - Tutorialspoint
-
How To Use C# String Substring
-
C# Substring Examples - Dot Net Perls
-
C# Substring 문자열 자르기 - 개발인생
-
How To Get A Substring From A String In C#
-
C# String SubString() Method - Javatpoint
-
082 - How To Use C# String Substring - YouTube
-
What Is Substring In C# With Example? [60 Answers Found]
-
How To Check If String Contains Specified Substring In C#?
-
Visual C# .net Strings - Substring - Home And Learn Courses