【问题标题】:Indexes in strings [closed]字符串中的索引[关闭]
【发布时间】:2016-07-09 02:36:19
【问题描述】:

我有:

str = "something"
str[0, 1] #=> "s"
str[0, 2] #=> "so"
str[3, 4] #=> "ethi"
str[2, 3] #=> "meth"

我看不出这其中的逻辑。这个双索引返回什么?

【问题讨论】:

  • 你试过阅读documentation吗?对我来说似乎很清楚。
  • 无法复制。

标签: ruby


【解决方案1】:

str[2,3]"met"。在这种形式中,它是str[zero_based_start_position, number_of_characters]

ruby documentation on String class

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-04
    • 1970-01-01
    • 2017-05-26
    • 1970-01-01
    相关资源
    最近更新 更多