Advertisement
DyNaMiXx7

Untitled

Mar 30th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.76 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _03ExtractFile
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string path = Console.ReadLine();
  11.             string pattern = @"(?<=^|\\)(?<group2>[\w.]{1,})$";
  12.  
  13.             var regex = Regex.Matches(path, pattern);
  14.  
  15.             foreach (Match element in regex)
  16.             {
  17.                 var file = element.Groups["group2"].Value;
  18.                 string[] fileAsArray = file.Split(".");
  19.                 string filename = fileAsArray[0];
  20.                 string extension = fileAsArray[1];
  21.  
  22.                 Console.WriteLine($"File name: {filename}");
  23.                 Console.WriteLine($"File extension: {extension}");
  24.             }
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement