Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我从这样的用户那里获取一个字符串变量:
mail = gets
我想用这个变量打开一个文件。
file = File.new(mail, "r") ##obviously this isn't working
我如何实际使用此邮件变量来打开该名称的文件?
谢谢
mail = gets.chomp
gets 函数给出一个以 \n 结尾的字符串。
我更喜欢mail = gets.strip.
mail = gets.strip
strip似乎比它稍慢,但chomp我发现它更具可读性。
strip
chomp
如果您对基准感到好奇,请在此处查看要点。