본문 바로가기

study/java

자바 코딩 테스트 삽질 - 마침표로 split 하기

코딩 테스트에서 마침표 . 를 갖고 split을 했더니 계속 안됐다.

온라인 에디터를 사용해서 그런 것인줄 알았는데 그게 아니라 split("\\.")으로 했어야 했다.

 

스택오버플로우에서 찾아보니 특수문자여서 그렇다고 한다. 심지어 \.으로 인식이 안됐다.

 

역슬래쉬+역슬래쉬+마침표 -> 이렇게 split해야 된다.

 

stackoverflow.com/questions/14833008/java-string-split-with-dot

 

Java string split with "." (dot)

Why does the second line of this code throw ArrayIndexOutOfBoundsException? String filename = "D:/some folder/001.docx"; String extensionRemoved = filename.split(".")[0]; While this works: String

stackoverflow.com