Added capitalize() and capwords().

This commit is contained in:
Guido van Rossum 1996-06-11 18:43:00 +00:00
parent 2e1beeac2e
commit 8775d8b9dc
2 changed files with 20 additions and 0 deletions

View File

@ -262,6 +262,16 @@ def translate(s, table):
res = res + table[ord(c)] res = res + table[ord(c)]
return res return res
# Capitalize a string, e.g. "aBc dEf" -> "Abc def".
def capitalize(s):
return upper(s[:1]) + lower(s[1:])
# Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def".
# See also regsub.capwords().
def capwords(s):
return join(map(capitalize, split(s)))
# Try importing optional built-in module "strop" -- if it exists, # Try importing optional built-in module "strop" -- if it exists,
# it redefines some string operations that are 100-1000 times faster. # it redefines some string operations that are 100-1000 times faster.
# It also defines values for whitespace, lowercase and uppercase # It also defines values for whitespace, lowercase and uppercase

View File

@ -262,6 +262,16 @@ def translate(s, table):
res = res + table[ord(c)] res = res + table[ord(c)]
return res return res
# Capitalize a string, e.g. "aBc dEf" -> "Abc def".
def capitalize(s):
return upper(s[:1]) + lower(s[1:])
# Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def".
# See also regsub.capwords().
def capwords(s):
return join(map(capitalize, split(s)))
# Try importing optional built-in module "strop" -- if it exists, # Try importing optional built-in module "strop" -- if it exists,
# it redefines some string operations that are 100-1000 times faster. # it redefines some string operations that are 100-1000 times faster.
# It also defines values for whitespace, lowercase and uppercase # It also defines values for whitespace, lowercase and uppercase