Function to convert a string to lower or upper case