Title Description
Suppose there is a string that contains the file name, extension name and path, as strFileName = @ "D: \ C # programming \ Experiment 3 \ MyFile.TXT". Use C # to write a static method that can be taken in the path of the file name "MyFile.TXT".
Entry
It contains a file name, extension name and path of the string.
Export
Filename string.
Sample input
strFileName = @ "D: \ C # Programming \ experiment 3 \ MyFile.TXT"
Sample Output
MyFile.TXT
prompt
Tip: Use string class lastindexof and substring methods to achieve.
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace extract the file name { class Program { static void Main(string[] args) { try { string s = Console.ReadLine(); int start = s.LastIndexOf("MyFile.TXT"); //Console.WriteLine(start); string new_s = s.Substring(start,10); Console.WriteLine(new_s); } catch(Exception) { Console.WriteLine("error"); } Console.ReadKey(); } } }