要从字符串中获取最后一个n字符,我假设您可以使用
n
ending = string[-n..-1]
但是,如果字符串长度小于n个字母,则会得到nil。
nil
有哪些可用的解决方法?
Background:字符串是纯ASCII码,我可以访问Ruby1.9.1,并且我使用的是plain Old ruby对象(没有web框架)。
https://stackoverflow.com/questions/2174767
相似问题