BACK-END/Java

replace what?!

02:00AM 2022. 1. 14. 12:41

여러 정보를 취합할때 ":" 혹은 "."과 같은 정보를 빼고 PlainText정보만 취합하고자 할때가 있다.

toString().replace("-",""); 

이런식으로 해도 무방하다.

 

여러개 하고 싶다면 .replace("타켓","변경하고자하는 text")

public static String localDateTimeToPlainText(LocalDateTime localDateTime) {

        return localDateTime.toString()
                .replace("-", "")
                .replace(":", "")
                .replace(".", "");
    }

이런식으로 하면 LocalDateTime에 빼고 싶은 내용을 없앨수 있다.

'BACK-END > Java' 카테고리의 다른 글

How to get the foreach index in java.  (0) 2022.01.15
Qrcode & barcode 생성  (0) 2022.01.12