The standard library’s string methods provide many useful string-related functions. Here are some examples to give you a sense of these methods.
To run the program, save it as string-functions.ts and use ts-node (assuming you have TypeScript and ts-node installed):
Note that TypeScript, being a superset of JavaScript, uses the built-in String methods. Some methods like Count don’t have direct equivalents, so we’ve used a combination of split and length to achieve the same result. The Replace method in TypeScript only replaces the first occurrence by default, so we’ve shown both the global replacement (using a regular expression) and the single replacement.