Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -module(letters).
- -export([convert_case/1]).
- % Empty list handler
- convert_case( [] )->
- [];
- % If the ascii value is between 'a' and 'z', convert to upper case
- convert_case( [H|T] ) when H>96, H<123 ->
- [to_upper(H)|convert_case(T)];
- % If the ascii value is between 'A' and 'Z', convert to lower case
- convert_case( [H|T] ) when H>64, H<91 ->
- [to_lower(H)|convert_case(T)];
- % Else, leave it alone
- convert_case( [H|T] ) ->
- [H|convert_case(T)].
- % Convert to upper case
- to_upper( X ) ->
- X-32.
- % Convert to lower case
- to_lower( X ) ->
- X+32.
Add Comment
Please, Sign In to add comment