Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make the first letter of a string uppercase? [duplicate]

Tags:

javascript

Possible Duplicate:
Capitalize first letter of string in javascript

How do I make the first letter of a string uppercase?

like image 691
David G Avatar asked May 04 '11 16:05

David G


People also ask

How do you make the first letter of a string uppercase?

The toUpperCase() method converts the string to uppercase. Here, str. charAt(0). toUpperCase(); gives J.

How do you make the first letter uppercase in C++?

Using toupper() function The standard solution to convert a lowercase letter to uppercase is using the toupper() function from <cctype> header. The idea is to extract the first letter from the given string, and convert it to uppercase. This works in-place, since strings are mutable in C++.

How do you capitalize the first letter of a word in Python?

string capitalize() in Python Python String capitalize() method returns a copy of the original string and converts the first character of the string to a capital (uppercase) letter, while making all other characters in the string lowercase letters.

How do you create a character in a string uppercase?

toUpperCase(char ch) converts the character argument to uppercase using case mapping information from the UnicodeData file.


1 Answers

Here's a function that does it

function firstToUpperCase( str ) {
    return str.substr(0, 1).toUpperCase() + str.substr(1);
}

var str = 'hello, I\'m a string';
var uc_str = firstToUpperCase( str );

console.log( uc_str ); //Hello, I'm a string
like image 111
meouw Avatar answered Oct 13 '22 02:10

meouw