EN
TypeScript - get substring between two characters
0 points
In this article, we would like to show you how to get substring between two characters using TypeScript.
Quick solution:
xxxxxxxxxx
1
text.substring(indexStart, indexEnd);
In this example, we use indexOf()
method to get the indexes of the characters between which we want to get our result
substring. Then we use substring()
method to get the result
.
Runnable example:
xxxxxxxxxx
1
const text: string = 'Get the text:example_text.';
2
3
const indexStart: number = text.indexOf(':') + 1;
4
const indexEnd: number = text.indexOf('.');
5
6
const result: string = text.substring(indexStart, indexEnd);
7
console.log(result); // example_text