本文介绍了Ruby“.downcase!"和“小写"困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚开始 Ruby 编程.我读过 小写和小写之间的区别!在 Ruby 中.然而我在实践中遇到了一个有趣的问题,这里是代码:
I just started Ruby programming. I had read Difference Between downcase and downcase! in Ruby. However I encounter an interesting problem in practice, here is code:
a = "lower"
a = a.downcase
print a
Compiler return: lower
但是,如果我尝试:
a = "lower"
a = a.downcase!
print a
Compiler return: nil
但是,如果a = LOWER",两个版本的代码都返回lower"
However, both version of code returns "lower" if "a = LOWER"
推荐答案
将 str 的内容小写,如果未进行任何更改,则返回 nil.注意:大小写替换仅在 ASCII 区域有效.
Downcases the contents of str, returning nil if no changes were made. Note: case replacement is effective only in ASCII region.
这篇关于Ruby“.downcase!"和“小写"困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!