C#-#TIP에서 확장자 없는 파일 이름 가져오기

요 며칠 나는 확장자 없이 파일 이름을 어떻게 얻는지 스스로에게 물었다.나는 이 문제를 정규 표현식으로 해결하고 싶다는 것을 인정한다.
걱정 마세요.System.IO.Path에는 이런 상황을 전문적으로 겨냥한 방법이 있다.
using System.IO;

///
/// Get file name without extension
///
static string GetFileName(string path)
{
    return Path.GetFileNameWithoutExtension(path);
}

///
/// Get file name without extension
///
static string GetFileName(FileInfo fileInfo)
{
    return Path.GetFileNameWithoutExtension(fileInfo.Name);
}
이 답안은 Stack Overflow 포럼에서 인정받았다.
Getting file names without extensions

좋은 웹페이지 즐겨찾기