Get file extension (the stuff behind that '.'), e.g. "test.bmp" will return "bmp" - CSharp System.IO

CSharp examples for System.IO:File Path

Description

Get file extension (the stuff behind that '.'), e.g. "test.bmp" will return "bmp"

Demo Code


using System.Text;
using System.Linq;
using System.IO;// w w w .  j  ava2 s .  c o  m
using System.Collections.Generic;
using System.Collections;
using System;

public class Main{
        /// <summary>
        /// Get extension (the stuff behind that '.'),
        /// e.g. "test.bmp" will return "bmp"
        /// </summary>
        static public string GetExtension(string file)
        {
            if (file == null)
                return "";
            int l = file.LastIndexOf('.');
            if (l > 0 && l < file.Length)
                return file.Remove(0, l + 1);
            return "";
        } // GetExtension(file)
}

Related Tutorials