Text file:

Party Rock Anthem/LMFAO/2011
Somebody That I Used To Know/Gotye/2012
We Found Love/Rihanna/2011
Rolling in the Deep/Adele/2011
Blurred Lines/Robin Thicke/2013
Call Me Maybe/Carly Rae Jepsen/2012
Happy/Pharrell Williams/2014
Royals/Lorde/2013
Dark Horse/Katy Perry/2014
Moves Like Jagger/Maroon 5/2011

Ruby code

hits = File.open("hits.txt") do |f|

  f.inject(0) do |count, line|
    arrLine = line.split("/")
    puts "\"#{arrLine[0]},\" performed by #{arrLine[1]}, #{arrLine[2]}"
  end
end

Outputs:

“Somebody That I Used To Know,” performed by Gotye, 2012
“We Found Love,” performed by Rihanna, 2011
“Rolling in the Deep,” performed by Adele, 2011
“Blurred Lines,” performed by Robin Thicke, 2013
“Call Me Maybe,” performed by Carly Rae Jepsen, 2012
“Happy,” performed by Pharrell Williams, 2014
“Royals,” performed by Lorde, 2013
“Dark Horse,” performed by Katy Perry, 2014

artpes57

Author artpes57

More posts by artpes57

Leave a Reply

All rights reserved Salient.