티스토리 뷰

공부

[kotlin] remove trail slash

승가비 2022. 11. 18. 13:52
728x90
    fun removeTrailSlash(s: String): String {
        return s.replace(Regex("/$"), "")
    }

    fun String.removeTrailSlash(): String {
        return CommonUtil.removeTrailSlash(this)
    }
    @Test
    fun removeTrailSlash() {
        // given
        val expected = "asdf/qwer"
        val s = "$expected/"
        // when
        val actual = CommonUtil.removeTrailSlash(s)
        // then
        assertEquals(expected, actual)
    }
    
    @Test
    fun removeTrailSlash() {
        // given
        val expected = "asdf/qwer"
        val s = "$expected/"
        // when
        val actual = s.removeTrailSlash()
        // then
        Assertions.assertEquals(expected, actual)
    }

https://stackoverflow.com/questions/5437158/remove-a-trailing-slash-from-a-stringchanged-from-url-type-in-java/74485056#74485056

 

Remove a trailing slash from a string(changed from url type) in JAVA

I want to remove the trailing slash from a string in Java. I want to check if the string ends with a url, and if it does, i want to remove it. Here is what I have: String s = "http://almaden.ib...

stackoverflow.com

 

728x90

'공부' 카테고리의 다른 글

[docker] RUN, CMD, ENTRYPOINT  (0) 2022.11.21
[kotlin] timestamp  (0) 2022.11.21
[jenkins] timezone 설정  (0) 2022.11.18
[Spark] Executor Memory  (0) 2022.11.08
[Docker] Multi-stage builds  (0) 2022.11.08
댓글