I am trying to remove the last occurrence of a character in a string. I can get its index
:
str.lastIndexOf(',')
I have already tried to use split
and the replace
function on the string.
You could use patch
.
scala> val s = "s;dfkj;w;erw"
s: String = s;dfkj;w;erw
scala> s.patch(s.lastIndexOf(';'), "", 1)
res6: String = s;dfkj;werw
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With