Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capitalize first letter of a string using Angular or typescript [duplicate]

How can I capitalize the first letter of a string using Angular or typescript?

like image 807
user2004 Avatar asked Mar 15 '18 10:03

user2004


People also ask

How do I make the first letter capital of a string in TypeScript?

To capitalize the first letter of a string in TypeScript: Call the toUpperCase() method on the letter.

How will you capitalize the first letter of string?

To capitalize the first character of a string, We can use the charAt() to separate the first character and then use the toUpperCase() function to capitalize it.

How do you capitalize one character in a string?

The simplest way to capitalize the first letter of a string in Java is by using the String. substring() method: String str = "hello world!"; // capitalize first letter String output = str. substring(0, 1).


2 Answers

function titleCaseWord(word: string) {   if (!word) return word;   return word[0].toUpperCase() + word.substr(1).toLowerCase(); } 

You can also use in template TitleCasePipe

Some component template:

{{value |titlecase}} 
like image 174
Yerkon Avatar answered Oct 13 '22 00:10

Yerkon


 let str:string = 'hello';  str = str[0].toUpperCase() + str.slice(1); 
like image 28
Steve Ruben Avatar answered Oct 13 '22 00:10

Steve Ruben