Ruby string function


#1

hi

i am writing code in ruby which for converting

amjad_alI_khAn\khamAj-4.amjad_alI_khAn.zakir_hussain_and_the_maestros_3.mp3

format from file to

Zakir Hussain And The Maestros 3\Khamaj 4 - Amjad Ali K. (Zakir
Hussain And The Maestros 3).mp3

such as
1)remove _ and replace by space
2)make first letter capital of each letter

and store this format in another file
can anyone help me


#2

Nilesh K. wrote:

hi

i am writing code in ruby which for converting

amjad_alI_khAn\khamAj-4.amjad_alI_khAn.zakir_hussain_and_the_maestros_3.mp3

format from file to

Zakir Hussain And The Maestros 3\Khamaj 4 - Amjad Ali K. (Zakir
Hussain And The Maestros 3).mp3

such as
1)remove _ and replace by space
2)make first letter capital of each letter

and store this format in another file
can anyone help me

str =
‘amjad_alI_khAn\khamAj-4.amjad_alI_khAn.zakir_hussain_and_the_maestros_3.mp3’

new_str = str.gsub("_", " ")
puts new_str

new_str = new_str.gsub(/\w*/) do |match|
match.capitalize
end
puts new_str

new_str = new_str.gsub("-", " ")
puts new_str

pieces = new_str.split(/.|\/) #split on . or
p pieces

result1 = pieces[3]
result2 = pieces[1]
result3 = pieces[2]
result4 = pieces[3]
result5 = pieces[4].downcase

puts “#{result1}\#{result2} - #{result3} (#{result4}).#{result5}”

–output:–
amjad alI khAn\khamAj-4.amjad alI khAn.zakir hussain and the maestros
3.mp3
Amjad Ali K.\Khamaj-4.Amjad Ali K…Zakir Hussain And The Maestros
3.Mp3
Amjad Ali K.\Khamaj 4.Amjad Ali K…Zakir Hussain And The Maestros
3.Mp3
[“Amjad Ali K.”, “Khamaj 4”, “Amjad Ali K.”, “Zakir Hussain And The
Maestros 3”, “Mp3”]
Zakir Hussain And The Maestros 3\Khamaj 4 - Amjad Ali K. (Zakir
Hussain And The Maestros 3).mp3