Last active
December 26, 2015 22:39
-
-
Save stevencombs/7224802 to your computer and use it in GitHub Desktop.
Request multi word input and request a word to redact from the input. Redacted word will be replaced with "REDACTED" unless word to redact was not found in which case the string will print intact.
This file contains 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
# Ruby Getting Started with Programming | |
# A Codecademy Ruby (Redacted) assignment | |
# Dr. Steven B. Combs, coding novice | |
puts "Text to search through: " #Puts text | |
text = gets.chomp #Request input and "chomp" return | |
puts "Word to redact: " #Puts text | |
redact = gets.chomp #Request second input and "chomp" return | |
words = text.split (" ") #Splits the input into words at each space | |
words.each do |word| #Loop for each word in variable words and place word in variable word | |
if word != redact #If word (from split of words) is not equal to "redact" | |
print word + " " #Print word and a space (used to separate the splits) | |
else #If words split is equal to the redact word | |
print "REDACTED " #Print "REDACTED" in place of the word | |
end #End if | |
end #End .each loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment