Some String methods.

Formatting

capitalize

the first character is converted to uppercase and all others to lowercase

 "hello".capitalize   # => "Hello"
 "Hello".capitalize   # => "Hello"
 "hELLO".capitalize   # => "Hello"
" HELLO".capitalize   # => " hello"
"1HELLO".capitalize   # => "1hello"

downcase

replace all uppercase letters with their lowercase counterparts

  "Hello".downcase   # => "hello"
  "heLLO".downcase   # => "hello"
" heLLO ".downcase   # => " hello "

see also upcase

lstrip

left strip - remove leading whitespace

        "  hello".lstrip   # => "hello"
        "hello  ".lstrip   # => "hello  "
      "  hello  ".lstrip   # => "hello  "
         "\r\t\n".lstrip   # => ""
"\r\t\nhello\v\f".lstrip   # => "hello\v\f"

see also strip and rstrip

rstrip

right strip - remove trailing whitespace

        "  hello".rstrip   # => "  hello"
        "hello  ".rstrip   # => "hello"
      "  hello  ".rstrip   # => "  hello"
         "\r\t\n".rstrip   # => ""
"\r\t\nhello\v\f".rstrip   # => "\r\t\nhello"

see also strip and lstrip

strip

remove leading and trailing whitespace

        "  hello".strip   # => "hello"
        "hello  ".strip   # => "hello"
      "  hello  ".strip   # => "hello"
         "\r\t\n".strip   # => ""
"\r\t\nhello\v\f".strip   # => "hello"

see also lstrip and rstrip

upcase

replace all lowercase letters with their uppercase counterparts

  "Hello".upcase   # => "HELLO"
  "heLLO".upcase   # => "HELLO"
" heLLO ".upcase   # => " HELLO "

see also downcase