ruby on rails中怎样去掉字符串结尾处的回车

Python023

ruby on rails中怎样去掉字符串结尾处的回车,第1张

ruby的String类有一个方法叫chomp,用来去掉字符串末尾的\n或\r

例子这样

"hello".chomp #=>"hello"

"hello\n".chomp #=>"hello"

"hello\r\n".chomp #=>"hello"

"hello\n\r".chomp #=>"hello\n"

"hello\r".chomp #=>"hello"

ruby interpreter?

是Interactive Ruby 还是 Start Command Promt with Ruby?

我用的版本是ruby1.9.2

你要不试下Dos命令看能不能执行

程序(比如 helloworld.rb)复制到C:\Documents and Settings\Administrator

然后找到:开始-程序-附件-命令提示符 (或开始-运行-输入'cmd'回车确定)

输入helloworld回车

看看能不能运行