Using this sample code
paragraph = "champion xylophone excellent"
paragraph = paragraph.gsub("ch","tj")
words = paragraph.split(/ /)
words.each do |word|
if word[0,1] == "x"
word[0.1] = "z"
end
end
paragraph = words.join(" ")
paragraph.gsub("x","ks")
print paragraph
The result will be "tyampion zylophone excellent", not "tjampion zylophone exksellent"
The same applies if gsub is applied in each of them to separate words. I do not understand why he acts at the beginning, but not at the end.
Edit
The second case is a separate question from the first:
paragraph = "champion xylophone excellent"
paragraph = paragraph.gsub("ch","tj")
words = paragraph.split(/ /)
words.each do |word|
if word[0,1] == "x"
word[0.1] = "z"
end
word = word.gsub("x","ks")
end
paragraph = words.join(" ")
print paragraph
source
share