Reputation: 17963
What is an idiomatic way to find the index of a Char
in a scala String
starting from the right side of the String (instead of starting from the left side using indexOf
)?
Examples:
def indexOfFromRight(s: String, c: Char): Int = ???
assert(indexOfFromRight("iii", 'i') == 2)
assert(indexOfFromRight("abbabb", 'a') == 3)
assert(indexOfFromRight("foobar", 'x') == -1)
Thank you in advance for your consideration and response.
Upvotes: 1
Views: 627
Reputation: 17963
As commented: the lastIndexOf
method of String accomplishes the right side find.
Upvotes: 2