Is there any stdlib alternative?
fun String.appendIfMissing(suffix: String) = if (endsWith(suffix)) this else (this + suffix)
fun String.prependIfMissing(prefix: String) = if (startsWith(prefix)) this else (prefix + this)
used them in almost all my projects for various purposes. Especially in places where using Path/URL is impossible/undesirable, something like path.appendIfMissing("/")
See also: Apache StringUtils