Last excersize


#1



https://www.codecademy.com/en/courses/ruby-beginner-en-mzrZ6/0/6?curriculum_id=5059f8619189a5000201fbcb


Hello. I am attempting to write this code can take multiple, seperate words to react.

As well as how to safe the redracted string as a variable instead of printing but I'm on the former part first.

At the moment when I type it in, this is what happens.
Please input
Hello there good sir
What is the redact?
good sir
Hello Hello there there REDACTED good sir REDACTED ["Hello", "there", "good", "sir"]

And if I type 3 words that would be redacted instead of two, it prints everything three times excluding one fo the redacted words as REDACTED. Not sure why. Thank you for any help.

Replace this line with your code. 
puts "Please input"
text = gets.chomp
puts "What is the redact?"
redact= gets.chomp

words= text.split (" ")

all_redacts= redact.split (" ")

words.each do |x|
all_redacts.each do |y|
    if x == y
        print "REDACTED "
    else 
        print x + " "
    end
end
end


#2

@microplayer83278,
If you want to replace a string consisting of multiple words
you will end up, using

text="This is this is a test text this"
the_str = "this is"
new_contents = text.gsub(/#{the_str}/, "replacement string")

#3

Thank you for your help.

Up to this point in the lessons, I haven't seen a solution like that. And I am wondering why the string is outputting multiple words when I have multiple words that will Redact, and only then.

I want to learn why every little thing is happening that I don't understand, I'm guessing this won't give me that it's just a quick gloss over but when it invites me to do something I would think the solution would require something it has taught or hinted at.

Frustrating!! I guess it's part of the process. Thanks again.


#4

@microplayer83278,
You could use the site stackoverflow.com to read on articles written by programmers.
== discussions / opinions ==
ruby [your question] site:stackoverflow.com