86
1
using System;
2
using System.IO;
3
using System.Diagnostics;
4
5
public static class StringExtension
6
{
7
/// <summary>
8
/// Get filename extension, not ext of . only returns empty string, mirrors Path.GetExtension not try/catch issues by metadataconsulting.blogspot.com
9
/// </summary>
10
/// <param name="s"></param>
11
/// <returns></returns>
12
public static string GetFileNameExtension(this string s)
13
{
14
string ext = "";
15
int fileExtPos = s.LastIndexOf('.');
16
if (fileExtPos > s.LastIndexOf('\\'))
17
{
18
ext = s.Substring(fileExtPos, s.Length - fileExtPos);
19
if (ext.Length <= 1) ext = "";
20
}
21
else
22
ext = "";
23
return ext;
24
}
Cached Result