Possible Duplicate:
How to capitalize the first letter of each word in a string (Python)?
Is there an option to convert a string such that the first letter is uppercase and everythingelse is lower case....like below..i know there are upper and lower for converting to uppercase and lowercase....
string.upper() //for uppercase string.lower() //for lowercase string.lower() //for lowercase INPUT:-italic,ITALIC OUTPUT:-Italic
http://docs.python.org/2/library/stdtypes.html
The toLowerCase method converts a string to lowercase letters. The toLowerCase() method doesn't take in any parameters. Strings in JavaScript are immutable. The toLowerCase() method converts the string specified into a new one that consists of only lowercase letters and returns that value.
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. Now, we would get the remaining characters of the string using the slice() function.
In cell B2, type =PROPER(A2), then press Enter. This formula converts the name in cell A2 from uppercase to proper case. To convert the text to lowercase, type =LOWER(A2) instead. Use =UPPER(A2) in cases where you need to convert text to uppercase, replacing A2 with the appropriate cell reference.
To capitalize the first letter of a string and lowercase the rest, use the charAt() method to access the character at index 0 and capitalize it using the toUpperCase() method. Then concatenate the result with using the slice() method to to lowercase the rest of the string. Copied!
Just use str.title()
:
In [73]: a, b = "italic","ITALIC"
In [74]: a.title(), b.title()
Out[74]: ('Italic', 'Italic')
help() on str.title()
:
S.title() -> string
Return a titlecased version of S, i.e. words start with uppercase
characters, all remaining cased characters have lowercase.
Yeah, just use the capitalize() method.
eg:
x = "hello"
x.capitalize()
print x #prints Hello
Title will actually capitalize every word as if it were a title. Capitalize will only capitalize the first letter in a string.
A simple way to do it:
my_string = 'italic'
newstr = my_string[0]
newstr = newstr.upper()
my_string = newstr + my_string[1:]
To make them lowercase (except the first letter):
my_string= 'ITALIC'
newstr = my_string[1:]
newstr = newstr.lower()
my_string = my_string[0] + newstr
I don't know if there is a built in to do this, but this should work.
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