EN
TypeScript - index of text in string after indicated position
0 points
In this short article, we would like to show how in TypeScript, find text in a string, looking from indicated position.
Quick solution:
xxxxxxxxxx
1
// ONLINE-RUNNER:browser;
2
3
// We are looking for `is` text position, starting from index 4.
4
5
// This one
6
// | |
7
// v v
8
const text: string = 'This is some example text.';
9
10
const startIndex: number = 4;
11
const foundIndex: number = text.indexOf('is', startIndex);
12
13
console.log(foundIndex); // 5
Output:
xxxxxxxxxx
1
5