Change Case of a String

Routine Summary

Converts a string to lower/upper case.

Inputs

Str1 - The string to convert
A - The case to convert to: 0 for lower, 1 for upper

Outputs

Ans or Str1- The converted string

Variables Used

Str1, Str2, A, B, N

Calculator Compatibility

TI-83/84/+/SE/CSE/CE

Authors

Electromagnet8

URL: Cemetech

" "+Str1+" →Str1 
length(Ans→B 
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz→Str2 
For(N,2,B 
inString(sub(Str2,1+A26,26),sub(Str1,N,1 
If Ans 
sub(Str1,1,N-1)+sub(Str2,Ans+not(A)26,1)+sub(Str1,N+1,B-N→Str1 
End 
sub(Str1,2,B-2→Str1

We pad the string with spaces to prevent a domain error.

With our string stored in Str1, we loop through each character in order.

To convert to lowercase, we search for the uppercase characters in Str2.
To convert to uppercase, we search for the lowercase characters in Str2.

If it finds the other case character, we replace that character with the other case character. Otherwise, we skip the code to replace.

Example use:

"helLO wOrld"
converted to lowercase is
"hello world"

"H^:'[]{}/ello* world"
converted to uppercase is
"H^:'[]{}/ELLO* WORLD"

.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial 2.5 License.