If I have a string saying \"abc.txt\"
, is there a quick way to get a substring that is just \"abc\"
?
I can\'t do an fileName.IndexOf(
///
/// Get the extension from the given filename
///
/// the given filename ie:abc.123.txt
/// the extension ie:txt
public static string GetFileExtension(this string fileName)
{
string ext = string.Empty;
int fileExtPos = fileName.LastIndexOf(".", StringComparison.Ordinal);
if (fileExtPos >= 0)
ext = fileName.Substring(fileExtPos, fileName.Length - fileExtPos);
return ext;
}