]> granicus.if.org Git - python/commitdiff
Added capitalize() and capwords().
authorGuido van Rossum <guido@python.org>
Tue, 11 Jun 1996 18:43:00 +0000 (18:43 +0000)
committerGuido van Rossum <guido@python.org>
Tue, 11 Jun 1996 18:43:00 +0000 (18:43 +0000)
Lib/string.py
Lib/stringold.py

index c9593476df8044ae7370d4976c5bc00f41627181..edf24a4e2f621ff49f8c7e42cb364331b1afbdec 100644 (file)
@@ -262,6 +262,16 @@ def translate(s, table):
        res = res + table[ord(c)]
     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,
 # it redefines some string operations that are 100-1000 times faster.
 # It also defines values for whitespace, lowercase and uppercase
index c9593476df8044ae7370d4976c5bc00f41627181..edf24a4e2f621ff49f8c7e42cb364331b1afbdec 100644 (file)
@@ -262,6 +262,16 @@ def translate(s, table):
        res = res + table[ord(c)]
     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,
 # it redefines some string operations that are 100-1000 times faster.
 # It also defines values for whitespace, lowercase and uppercase