[英]Remove newlines in Ruby
Is there a way to write a very long xml request in multiple lines instead of just one? 有没有办法在多行而不是一行中编写一个非常长的xml请求? When I write it in multiple lines, the string is not accepted because of the newlines inserted.
当我以多行写入时,由于插入了换行符,因此不接受该字符串。 How can I add newlines in my text editor with adding the newlines in the actual program?
如何在文本编辑器中添加换行符并在实际程序中添加换行符? I am using sublime.
我正在使用崇高。
str = "this is \n multi-line \n text \n\n"
puts str
# this is
# multi-line
# text
Use gsub! 使用gsub! to modify the string
修改字符串
str.gsub!("\n","")
puts str # this is multi-line text
Use squish to remove all unnecessary white space 使用挤压去除所有不必要的空白区域
str = "this is \nmulti-line \n text \n\n"
puts str.squish # this is multi-line text
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.