简体   繁体   English

使用[1..n]从Ruby字符串中删除第一个字符

[英]Remove first character from Ruby string using [1..n]

I'm trying to basically trying to remove the . 我试图基本上试图删除. in the the string .extension 在字符串.extension

So I'm using 所以我正在使用

'.extension'[1..10] #gives extension

Of course this will work for 10 characters, how would I make it work for any length. 当然,这将适用于10个字符,我将如何使它适用于任何长度。 I dont know what to search for because I dont know what this array style [x..y] is called. 我不知道要搜索什么,因为我不知道这个数组样式[x..y]被调用了什么。

You can use negative indexes. 您可以使用负索引。 This will offset them from the end. 这将从最后抵消它们。 -1 is the last element, -2 is the second last and so on. -1是最后一个元素,-2是第二个元素,依此类推。

'.extension'[1..-1] # => extension

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM