Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

typescript
communitycreator

What is the string object in TypeScript?

Chibueze Sam-Obisike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

In TypeScript, string is a data type that represents the sequence of character values. string is a primitive data type that is used to store textual data.

string values are surrounded by singular quotation marks, '', or double quotation marks, "". An array of characters works the same as a string.

Syntax

let _name = new String(string);
// or 
let varname:string = "somevalue"; 

Template string

After the introduction of ES6, strings can be written between backticks (``) instead of single or double-quotes. The values of the variable can be accessed using ${} as part of the string itself.

Methods

The string object can be manipulated with methods, just like most objects. A few of these methods are as follows:

  1. charAt(): Returns the character at the specified index.

  2. charCodeAt(): Returns a numerical value for the Unicode value of the character at a given index.

  3. concat(): Combines the text of two strings and returns a new string.

  4. slice(): Extracts a section of a string and returns a new string.

  5. substr(): Returns the characters in a string, beginning at the specified location through the specified number of characters.

  6. toUpperCase(): Returns the calling string value converted to uppercase letters.

  7. replace(): Used to find a match between a regular expression and a string and to replace the matched substring with a new substring.

RELATED TAGS

typescript
communitycreator

CONTRIBUTOR

Chibueze Sam-Obisike

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring