“Baris baru di Ruby” Kode Jawaban

cara mendapatkan jalur baru untuk ditampilkan di rel

<%= obj.description %>
Even though your value may be "One  \t  \n  \n  Two", it will show up on the screen as "One Two".

To get those new line characters to actually separate the lines when displayed, you'll need to convert them to HTML before rendering:

<%= obj.description.gsub(/\n/, '<br/>') %>
Of course, if users are entering data that will be included in your HTML, you should be escaping the values to protect against XSS. If new lines are the only thing you need to support, it should be as simple as this:

<%= h(obj.description).gsub(/\n/, '<br/>') %>
Jake_bdr

Baris baru di Ruby

str = "hello world"
str_with_new_line = "hello world/n"

# You also can output values differently
# 1. print
# Outputs the value with no new line
# 2. puts 
# Outputs the value with new line

str1 = "hello"
str2 = "world"

puts str1
puts str2

# Output: hello
#         world


print str1
print str2

# Output: helloworld
schwarz_koder

Jawaban yang mirip dengan “Baris baru di Ruby”

Pertanyaan yang mirip dengan “Baris baru di Ruby”

Lebih banyak jawaban terkait untuk “Baris baru di Ruby” di Ruby

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya