31. 파일명 추출
.NET프로그래밍/C# 3.5 SP1 2009. 8. 7. 11:18 |using System;
public class 파일명추출
{
public static void Main()
{
//[Q] 아래 전체 경로가 입력되었을 때 파일명과 확장자 추출
//[1] Input
string dir = "C:\\Website\\RedPlus\\images\\test.gif";
string fullName = String.Empty;
string name = "";
string ext = name;
//[2] Process
// 전체파일명 : 마지막 \\ 위치값 +1한 위치부터 마지막까지 검색
fullName = dir.Substring(dir.LastIndexOf('\\') + 1);
name = fullName.Substring(0, fullName.LastIndexOf('.'));
ext = fullName.Substring(fullName.LastIndexOf('.') + 1);
//[3] Output
Console.WriteLine("전체 파일명 : {0}", fullName);
Console.WriteLine("순수 파일명 : {0}", name);
Console.WriteLine("확장자 : {0}", ext);
//[A]
// 전체 파일명 : test.gif
// 순수 파일명 : test
// 확장자 : gif
}
}
'.NET프로그래밍 > C# 3.5 SP1' 카테고리의 다른 글
33. 수학관련함수 (0) | 2009.08.07 |
---|---|
32. 스트링포맷(String.Format) (0) | 2009.08.07 |
30. 스트링(string)클래스 (0) | 2009.08.07 |
알고리즘 - 수열예제 (0) | 2009.08.06 |
알고리즘 - 7. 최빈값 (0) | 2009.08.06 |