Guest User

Untitled

a guest
Jan 21st, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 0.55 KB | None | 0 0
  1. -module(letters).
  2. -export([convert_case/1]).
  3.  
  4. % Empty list handler
  5. convert_case( [] )->
  6.     [];
  7.  
  8. % If the ascii value is between 'a' and 'z', convert to upper case
  9. convert_case( [H|T] ) when H>96, H<123 ->
  10.     [to_upper(H)|convert_case(T)];
  11. % If the ascii value is between 'A' and 'Z', convert to lower case
  12. convert_case( [H|T] ) when H>64, H<91 ->
  13.     [to_lower(H)|convert_case(T)];
  14. % Else, leave it alone
  15. convert_case( [H|T] ) ->
  16.     [H|convert_case(T)].
  17.  
  18.  
  19. % Convert to upper case
  20. to_upper( X ) ->
  21.     X-32.
  22. % Convert to lower case
  23. to_lower( X ) ->
  24.     X+32.
Add Comment
Please, Sign In to add comment