Skip to content

Instantly share code, notes, and snippets.

@hpjaj
Last active August 29, 2015 14:10
Show Gist options
  • Save hpjaj/c4c922067867242f599f to your computer and use it in GitHub Desktop.
Save hpjaj/c4c922067867242f599f to your computer and use it in GitHub Desktop.
Week 3 - 2e - Inserted Word
def find_and_replace_files_existing_string_with_new_string(filename, old_string, new_string)
original_file_content = File.read("#{filename}")
new_file_content = original_file_content.gsub(old_string, new_string)
File.write("#{filename}", new_file_content)
end
=begin
Here is the existing sample file entitled 'plain_text.txt':
text text text text text
text text text text text
text text word text text
text text text text text
text text text text text
=end
find_and_replace_files_existing_string_with_new_string('plain_text.txt','word', 'inserted word')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment