Case Changer
func alternateCase(input: String): String { var output: String = ""
for (var i = 0; i < input.length; i += 1) { if (input.get(i).lower() != input.get(i)) output += input.get(i).lower() else output += input.get(i).upper() }
return output}
print(alternateCase("Hello World!")) # hELLO wORLD!print(alternateCase("TeeEEEsssTTTtT!")) # tEEeeeSSStttTt!
This code loops over the input string and changes the case of each character to the opposite of what it is.
import random
func randomCase(input: String): String { var output: String = "" for (var i = 0; i < input.length; i += 1) { if (random.randint(1, 2) == 1) output += input.get(i).upper() else output += input.get(i).lower() }
return output}
print(randomCase("The quick brown fox jumps over the lazy dog!"))
This code loops over the input string, and randomly uppercases or lowercases the characters.