I have a common pattern where I want to operate on a string like abckey123 where I want to clear the string before key but also remove the key.
Is there a commonly accepted way to do this? Or even better a way to make this a single method call on all string objects?
Ideas:
item.replaceBefore("key", "").replace("key", "")
item.split("key").last()
If you want to get all text after the "key" substring, you can use substringAfter function:
val result = item.substringAfter("key")
The second parameter of this function allows to specify what to return if the delimiter is not found. By default it returns the entire string, but you can pass an empty string for example:
val result = item.substringAfter("key", "")
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