Difference between revisions of "Code Snippet: Changing Character Case"
From Coder Merlin
(Created page with "let string = "For the world is hollow, and I have touched the sky!" print(string.uppercased()) print(string.lowercased())") |
|||
(6 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
= Print characters in uppercase or lowercase = | |||
== Swift == | |||
<syntaxhighlight lang="swift"> | |||
let string = "For the world is hollow, and I have touched the sky!" | let string = "For the world is hollow, and I have touched the sky!" | ||
print(string.uppercased()) | print(string.uppercased()) | ||
print(string.lowercased()) | print(string.lowercased()) | ||
</syntaxhighlight> | |||
== Python == | |||
<syntaxhighlight lang="Python"> | |||
string = "For the world is hollow, and I have touched the sky!" | |||
print(string.upper()) | |||
print(string.lower()) | |||
</syntaxhighlight> | |||
== Bash == | |||
<syntaxhighlight lang="Bash"> | |||
#!/bin/bash | |||
string="For the world is hollow, and I have touched the sky!" | |||
echo ${string^^} | |||
echo ${string^l} | |||
</syntaxhighlight> | |||
== Common Lisp == | |||
<syntaxhighlight lang="lisp"> | |||
(let ((string "For the world is hollow, and I have touched the sky!")) | |||
(write-line (string-upcase string)) | |||
(write-line (string-downcase string))) | |||
</syntaxhighlight> | |||
== Java == | |||
<syntaxhighlight lang="Java"> | |||
String string = "For the world is hollow, and I have touched the sky!"; | |||
System.out.println(string.toUpperCase()); // "FOR THE WORLD IS HOLLOW, AND I HAVE TOUCHED THE SKY" | |||
System.out.println(string.toLowerCase()); // "for the world is hollow, and i have touched the sky" | |||
</syntaxhighlight> |
Latest revision as of 09:07, 19 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)))
Java[edit]
String string = "For the world is hollow, and I have touched the sky!";
System.out.println(string.toUpperCase()); // "FOR THE WORLD IS HOLLOW, AND I HAVE TOUCHED THE SKY"
System.out.println(string.toLowerCase()); // "for the world is hollow, and i have touched the sky"