Skip to content

Commit 5746494

Browse files
Helper function count occurencies (#1)
* Helper function count occurencies * Changed function name
1 parent 7132418 commit 5746494

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

general.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,14 @@ export function replaceStringEscapeCharacters(str: string, toEscaped: boolean =
163163
});
164164
}
165165
return str;
166-
}
166+
}
167+
168+
export function countOccurrences(str: string, search: string): number {
169+
let c = 0, p = -1;
170+
while (true) {
171+
p = str.indexOf(search, p + 1)
172+
if (p != -1) c++;
173+
else break;
174+
}
175+
return c;
176+
}

0 commit comments

Comments
 (0)