Advertisement
elena1234

ExtractFile*-withSubstring()

Nov 13th, 2020 (edited)
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace ExtractFile
  5. {
  6.     class MainClass
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             string text = Console.ReadLine();
  11.             int startIndexFileName = text.LastIndexOf('\\') + 1;
  12.             int endIndexFileName = text.LastIndexOf('.');
  13.             int fileNameLength = endIndexFileName - startIndexFileName;
  14.             string fileName = text.Substring(startIndexFileName, fileNameLength);
  15.  
  16.             int startIndexExtension = text.LastIndexOf('.')+1;
  17.             string extension = text.Substring(startIndexExtension);
  18.  
  19.             Console.WriteLine($"File name: {fileName}");
  20.             Console.WriteLine($"File extension: {extension}");
  21.         }
  22.     }
  23. }    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement