我也有一个带有不同数据和星星的字符串。如何获取最后一个 * 的索引?例如
hello * there * *
现在我怎样才能得到第三个*的索引?
Use String.rindex:
Returns the index of the last occurrence of the given substring or pattern (regexp) in str. Returns nil if not found.
x = 'hello * there * *'
puts x.rindex('*') # 16