How to remove string trailing path separator in Scala

2 Answers

0 votes
val path = "/directory/project/"
val cleanedPath = path.stripSuffix("/")

println(cleanedPath) 


 
/*
run:

/directory/project

*/

 



answered Jun 16, 2025 by avibootz
0 votes
val path = "/directory/project/"
val cleanedPath = path.replaceAll("/+$", "")

println(cleanedPath) 


 
/*
run:

/directory/project

*/

 



answered Jun 16, 2025 by avibootz

Related questions

...