Created
July 31, 2013 06:55
-
-
Save chiragmongia/6119898 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Question- Character Count - Ranges | |
| #Write a method that returns the no of various lowercase, uppercase, digits and special characters used in the string. Make use of Ranges. | |
| def character_count(input_string) | |
| lower, upper, number, special_character = 0, 0, 0, 0 | |
| splitted_string = input_string.split(//) | |
| for i in 0...splitted_string.size | |
| case splitted_string[i] | |
| when 'a'..'z' | |
| lower += 1 | |
| when 'A'..'Z' | |
| upper += 1 | |
| when '0'..'9' | |
| number += 1 | |
| else | |
| special_character += 1 | |
| end | |
| end | |
| "Lowecase- #{ lower } Uppercase- #{ upper } Digits- #{ number } Special Characters- #{ special_character }" | |
| end | |
| #Main | |
| p "Enter the string" | |
| input_string = gets.chomp | |
| p character_count(input_string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment