【问题标题】:Displaying a string unescaped in IRB or in general显示在 IRB 或一般情况下未转义的字符串
【发布时间】:2013-12-06 10:47:27
【问题描述】:

假设我有一个字符串"this\n\tis \"helpful\"",并且出于复制/粘贴原因,我希望它在终端中显示,未转义,即

this
  is "helpful"

这在终端中是否可行,无论是在 IRB 还是其他方式?

【问题讨论】:

  • 试试这个puts "this\n\tis \"helpful\""

标签: ruby string character-encoding terminal irb


【解决方案1】:
11:15:14lasto1.9.3 ~/clients  ?  irb
1.9.3-p448 :001 > s = "this\n\tis \"helpful\""
 => "this\n\tis \"helpful\""
1.9.3-p448 :002 > puts s
this
    is "helpful"
 => nil
1.9.3-p448 :003 >

【讨论】:

  • 哈,当然!我现在真的觉得很傻。我使用的是p 而不是put
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-06-12
  • 1970-01-01
  • 2023-03-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多