How do I remove a substring after a certain character in a string using Ruby?
I find that "Part1?Part2".split('?')[0]
is easier to read.
new_str = str.slice(0..(str.index('blah')))
I'm surprised nobody suggested to use 'gsub'
irb> "truncate".gsub(/a.*/, 'a')
=> "trunca"
The bang version of gsub can be used to modify the string.