programing

출력에서 줄 바꿈을 수행하는 방법

linuxpc 2023. 5. 31. 15:22
반응형

출력에서 줄 바꿈을 수행하는 방법

만드는 법\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'

저는 제 경험을 여러분과 나누고 싶습니다.\n
"\n"이 다음과 같이 작동한다는 것을 알게 되었습니다.

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

하지만 아닙니다.

p "\n\n"

또한 puts'\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"을 추가하는 것은 저에게 효과가 없었습니다.puts그래서 제가 해결책으로 전화했습니다.print"\n"을 주장으로 하는 다음 줄에서, 내가 방금 전화를 걸 수 있었다고 생각하지만.puts다시.

이 결과는 원하는 결과를 얻지 못했습니다.

puts "Coach says: #{coach_answer(user_input)}\n"

하지만 이는 다음과 같습니다.

puts "Coach says: #{coach_answer(user_input)}"
print "\n"

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

반응형