programing tip

출력에서 개행을 수행하는 방법

itbloger 2020. 6. 3. 21:29
반응형

출력에서 개행을 수행하는 방법


\n실제로 출력에서 어떻게 작동합니까? 현재는 단지 하나의 긴 블록으로 모든 것을 씁니다. 도움을 주셔서 감사합니다

Dir.chdir 'C:/Users/name/Music'
music = Dir['C:/Users/name/Music/*.{mp3, MP3}']
puts 'what would you like to call the playlist?'
@new = ''
playlist_name = gets.chomp + '.m3u'

music.each do |z|
  @new += z + '\n'
end

File.open playlist_name, 'w' do |f|
  f.write @new
end

"\n"대신 사용'\n'


File.open 블록에서이 작업을 모두 수행 할 수 있습니다.

Dir.chdir 'C:/Users/name/Music'
music = Dir['C:/Users/name/Music/*.{mp3, MP3}']
puts 'what would you like to call the playlist?'
playlist_name = gets.chomp + '.m3u'

File.open playlist_name, 'w' do |f|
  music.each do |z|
    f.puts z
  end
end

실제로는 블록이 필요하지 않습니다.

  Dir.chdir 'C:/Users/name/Music'
  music = Dir['C:/Users/name/Music/*.{mp3, MP3}']
  puts 'what would you like to call the playlist?'
  playlist_name = gets.chomp + '.m3u'

  File.open(playlist_name, 'w').puts(music)

나는 내 경험을 공유하고 싶습니다 \n
내가 통지 나니 "\ n"시스 - 작동

puts "\n\n" // to provide 2 new lines

하지만

p "\n\n"

또한두고 '\n\n'
합니까하지 작동합니다.

희망은 당신을 위해 일할 것입니다!

참고 URL : https://stackoverflow.com/questions/2060253/how-to-do-a-newline-in-output

반응형