开发者

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

开发者 https://www.devze.com 2023-03-03 21:24 出处:网络
I\'d like to get a substring from a string from position N to the 开发者_StackOverflow中文版end of the string.

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

精彩评论

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