Kalkwst / MicroLib

MIT License
3 stars 0 forks source link

:sparkles: Text: Add SwapCase method #14

Closed Kalkwst closed 1 year ago

Kalkwst commented 1 year ago

This method takes in a string, str, and returns a new string with the case of each character in str swapped. If the input string is empty or null, the original string is returned. Otherwise, the code loops through each character in the string and appends the character to a new string with the opposite case. If the character is uppercase, it is converted to lowercase and appended, and vice versa for lowercase characters. The code does not take into account whitespace or other non-letter characters.

This method can change the case of a string to make it easier to read or understand. For example, you might use this method to convert a long string of all uppercase letters to lowercase, or to convert a string with inconsistent case to a more standardized form.