A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Write a C# Sharp program to get the file name (including extension) from a given path
Q:

Write a C# Sharp program to get the file name (including extension) from a given path

0

Write a C# Sharp program to get the file name (including extension) from a given path

Sample Output:

test.cpp
abc.mp4
test.txt

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
using System.Linq;
namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            string file_path;
            file_path = "c:/csharp/ex/test.cpp";
            Console.WriteLine(test(file_path));                     
            file_path = "c:/movies/abc.mp4";
            Console.WriteLine(test(file_path));
            file_path = "test.txt";
            Console.WriteLine(test(file_path));            
        }
        public static string test(string file_path)
        {
            return file_path.Split('/').Last();
        }
    }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now