ruby string function

N

Nilesh Kulkarni

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 Khan (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
 
7

7stud --

Nilesh said:
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 Khan (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 Khan\Khamaj-4.Amjad Ali Khan.Zakir Hussain And The Maestros
3.Mp3
Amjad Ali Khan\Khamaj 4.Amjad Ali Khan.Zakir Hussain And The Maestros
3.Mp3
["Amjad Ali Khan", "Khamaj 4", "Amjad Ali Khan", "Zakir Hussain And The
Maestros 3", "Mp3"]
Zakir Hussain And The Maestros 3\Khamaj 4 - Amjad Ali Khan (Zakir
Hussain And The Maestros 3).mp3
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,965
Members
47,513
Latest member
JeremyLabo

Latest Threads

Top