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 |