https://kotlinlang.org logo
#random
Title
# random
l

LeoColman

02/02/2023, 2:32 PM
Is there a syntax for
removeThisCharacters
from an entire string?
"abc".replace("a", "")
vs an idealized
"abc".remove("a")
There is
removePrefix
,
removeSuffix
and
removeSurrounding
, but not a plain
remove
😞
l

Luke Armitage

02/02/2023, 2:39 PM
maybe write an extension function for partial application of
replace
to give you your idealised
remove
function? 🙂
l

LeoColman

02/02/2023, 2:44 PM
But then I'd have to maintain it! Can I sneak it into the STDLib instead? 🙊
😁 1
k

Klitos Kyriacou

02/02/2023, 3:12 PM
replace("a", "")
seems to be the most concise, but also consider
filter { it != 'a' }
to avoid having to turn the char 'a' into the string "a".
e

ephemient

02/02/2023, 8:47 PM
in principle, there could be implementations of
remove('a')
that are more efficient than
filter { it != 'a' }
. in practice, JVM doesn't have them so it doesn't matter
2 Views