Difference between revisions of "Code Snippet: Changing Character Case"

From Coder Merlin
(Added Bash version of changing character casing)
m (Replaced "Hello, World!" with the inherited string)
Line 26: Line 26:
== Common Lisp ==
== Common Lisp ==
<syntaxhighlight lang="lisp">
<syntaxhighlight lang="lisp">
(let ((string "Hello, world!"))
(let ((string "For the world is hollow, and I have touched the sky!"))
   (write-line (string-upcase string))
   (write-line (string-upcase string))
   (write-line (string-downcase string)))
   (write-line (string-downcase string)))
</syntaxhighlight>
</syntaxhighlight>

Revision as of 16:16, 12 September 2019

Within these castle walls be forged Mavens of Computer Science ...
— Merlin, The Coder

Print characters in uppercase or lowercase[edit]

Swift[edit]

let string = "For the world is hollow, and I have touched the sky!"
print(string.uppercased())
print(string.lowercased())

Python[edit]

string = "For the world is hollow, and I have touched the sky!"
print(string.upper())
print(string.lower())

Bash[edit]

#!/bin/bash

string="For the world is hollow, and I have touched the sky!"
echo ${string^^}
echo ${string^l}

Common Lisp[edit]

(let ((string "For the world is hollow, and I have touched the sky!"))
  (write-line (string-upcase string))
  (write-line (string-downcase string)))