标签: ruby
我有:
str = "something" str[0, 1] #=> "s" str[0, 2] #=> "so" str[3, 4] #=> "ethi" str[2, 3] #=> "meth"
我无法在此看到逻辑。这个双索引返回了什么?
答案 0 :(得分:3)
str[2,3]是"met"。在此表单中,它是str[zero_based_start_position, number_of_characters]
str[2,3]
"met"
str[zero_based_start_position, number_of_characters]
请参阅ruby documentation on String class