开发者

How can I get a substring from position N to the last char in Ruby?

I'd like to get a substring from a string from position N to the 开发者_StackOverflow中文版end of the string.

What's the way to do it in Ruby?


Just slice the string like:

string[N..-1]


or you can use the size : str[N,str.size-1]


As of Ruby 2.6, you can use endless range syntax for this:

string[N..]

where N is the start index. (No need to specify a -1 for the end index.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜