블로그 이미지
Magic_kit
study 관련자료를 한곳으로 자기 개발 목적으로 재태크 재무 관리 목적으로 일상생활의 팁을 공유 하기 위하여 블로그를 개설 하였습니다.

calendar

1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28

Category

Recent Post

Recent Comment

Archive

2009. 8. 10. 18:45 .Net Project/.Net C#
반응형

using System;

public class 파일명추출
{
    public static void Main(string[] args)
    {
        string dir = "C:\\Website\\RedPlus\\images\\test.gif";
        string fullName = string.Empty;    // 초기화
        string name = "";
        string ext = "";

        // 파일명 : test.gif
       // 가장뒤의 "\\"의 뒤부터 출력

        fullName = dir.Substring(dir.LastIndexOf("\\") + 1);
         // 파일명에서 0번 index 부터 "."의 index까지 출력
         // 확장자 : gif
         name = fullName.Substring(0, fullName.LastIndexOf(".")); 
      
         // 파일명에서 "." index 이후 출력
         ext = fullName.Substring(fullName.LastIndexOf(".") + 1);  
        Console.WriteLine("파일명 : {0}", fullName);
        Console.WriteLine("순수 파일명 : {0}", name);
        Console.WriteLine("확장자 : {0}", ext);
    }
}

반응형

'.Net Project > .Net C#' 카테고리의 다른 글

28장 Round (반올림)  (0) 2009.08.10
27장 Math(수학관련함수)  (0) 2009.08.10
25장 String Format  (0) 2009.08.10
24장 String Class(스트링 클래스)  (0) 2009.08.10
23장 알고리즘(간단수열)  (0) 2009.08.10
posted by Magic_kit