본문 바로가기
MEMO/기타

substring

by eungSe__ 2024. 5. 22.

.substring(단어시작 노드번호,검색할 단어갯수-생략시 전체갯수)

//파일속성
public void property() throws Exception{
    String url = "D:\\product\\pd1.jpg";
    File f = new File(url);
    System.out.println(f.getName()); //파일명을 가져와라

    //파일 속성명(확장자)만 가져오기
    String filename = f.getName();
    //해당 단어를 기준으로 맨 마지막에 해당되는 단어 노드번호
    int n = filename.lastIndexOf(".");
    //(단어시작 노드번호,검색할 단어갯수-생략시 전체갯수)
    String modify = filename.substring(n); //.jpg출력 
    System.out.println(modify);

}

 

'MEMO > 기타' 카테고리의 다른 글

sts 패키지명 path에서 제거  (0) 2024.05.31
SPA / MPA  (0) 2024.05.30
study git - source  (0) 2024.05.22
Git  (0) 2024.05.21
시험1  (0) 2024.05.14