Cut of file extension, e.g. "hi.txt" becomes "hi" - CSharp File IO

CSharp examples for File IO:File

Description

Cut of file extension, e.g. "hi.txt" becomes "hi"

Demo Code


using System.Text;
using System.Linq;
using System.IO;//from   w w  w  . ja  va 2  s.c o m
using System.Collections.Generic;
using System.Collections;
using System;

public class Main{
        /// <summary>
        /// Cut of extension, e.g. "hi.txt" becomes "hi"
        /// </summary>
        static public string CutExtension(string file)
        {
            if (file == null)
                return "";
            int l = file.LastIndexOf('.');
            if (l > 0)
                return file.Remove(l, file.Length - l);
            return file;
        } // CutExtension(file)
}

Related Tutorials