JulianJulianov

08.TextProcessingExercise-Extract File

Apr 19th, 2020
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. 08. Extract File
  2. Write a program that reads the path to a file and subtracts the file name and its extension.
  3. Examples
  4. Input                                                                 Output
  5. C:\Internal\training-internal\Template.pptx                           File name: Template
  6.                                                                       File extension: pptx
  7. C:\Projects\Data-Structures\LinkedList.cs                             File name: LinkedList
  8.                                                                       File extension: cs
  9. using System;
  10. using System.Linq;
  11.  
  12. public class Program
  13. {
  14.     public static void Main()
  15.     {
  16.          var pathToFile = Console.ReadLine().Split("\\");
  17.          var neededFile = pathToFile.Last().Split('.');
  18.        
  19.          Console.WriteLine($"File name: {neededFile[0]}");
  20.          Console.WriteLine($"File extension: {neededFile[1]}");
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment