(strcase string [flag])
Convert this string to all upper- or all lower-case.
This function converts text in a string to all upper-case or all lower-case (when flag is non-nil).
The case to be converted is specified by the flag argument. When omitted or set to nil, all characters are converted to upper-case. When not nil (T is typically used), all alphabetic characters are converted to lower-case.
Examples
Code | Returns |
---|---|
(strcase "Yes") | YES |
(strcase "NO" T) | "no" |
(setq var (strcase var)) | Permanently changes variable. |
(if (= (strcase var) "YES") (...) | Temporarily checks variable. |
NOTE LISP functions that check and compare text tend to be case-sensitive. For example, (if (= "Y" ans) ...) only works with a capital "Y"; a lowercase "y" is not considered the same. For this reason, it is useful to apply the strcase function to the user's response, as follows:
(setq ans (getchar))
(setq ans (strcase ans))
(if (= "Y" ans)
...
)