How to remove string trailing path separator in C#

1 Answer

0 votes
using System;
using System.IO;

class Program
{
    static void Main()
    {
        string path = @"C:\MyFolder\Project";

        // Remove trailing path separator
        string trimmedPath = path.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
        
        Console.WriteLine(trimmedPath);
    }
}



/*
run:

C:\MyFolder\Project

*/

 



answered Jun 16 by avibootz

Related questions

...