Last active
August 29, 2015 14:10
-
-
Save hpjaj/c4c922067867242f599f to your computer and use it in GitHub Desktop.
Week 3 - 2e - Inserted Word
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
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