Skip to content

Instantly share code, notes, and snippets.

@dvnmk
Last active August 29, 2015 14:13
Show Gist options
  • Save dvnmk/653f13e54707c13bed46 to your computer and use it in GitHub Desktop.
Save dvnmk/653f13e54707c13bed46 to your computer and use it in GitHub Desktop.
"aBcDe -> AbCdE"
(defun toggle-case (string)
""aBcDe1" -> "AbCdE1""
(do* ((i 0 (+ i 1))
(len (length string))
(res string))
((equal i len) res)
(let ((ele (aref string i)))
(if (< (char-code ele) 91) ; ascii A 65 ~ Z 90, a 97 ~ z 122
(setf (aref string i) (char-downcase ele))
(setf (aref string i) (char-upcase ele))))))
(toggle-case "aBcDe3")
"AbCdE3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment