Ruby: Learn Ruby in 24 Hours or Less - A Beginner’s Guide To Learning Ruby Programming Now (Ruby, Ruby Programming, Ruby Course) by Robert Dwight

Ruby: Learn Ruby in 24 Hours or Less - A Beginner’s Guide To Learning Ruby Programming Now (Ruby, Ruby Programming, Ruby Course) by Robert Dwight

Author:Robert Dwight [Dwight, Robert]
Language: eng
Format: azw3
Published: 2016-05-08T16:00:00+00:00


first_sample = “hit and run”

second_sample = first_sample.sub(/n/, “$”)

third_sample = first_sample.gsub(/n/, “$”)

puts “This line uses the sub method: #{second_sample}”

puts “This line uses the gsub method: #{third_sample}”

output:

This line uses the sub method: hit a$d run

This line uses the gsub method: hit a$d ru$

Pattern-Based Substitutions

You've learned how to perform string replacements using the sub/gsub methods. The examples given earlier involved fixed text. However, it's important to point out that substitution processes also work on other patterns (e.g. those that involve groupings, alterations and/or alternations). Analyze the following code:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.