Possible Duplicate:
Capitalize first letter of string in javascript
How do I make the first letter of a string uppercase?
The toUpperCase() method converts the string to uppercase. Here, str. charAt(0). toUpperCase(); gives J.
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++.
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.
toUpperCase(char ch) converts the character argument to uppercase using case mapping information from the UnicodeData file.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With