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, 2025 by avibootz

Related questions

1 answer 92 views
1 answer 102 views
2 answers 140 views
1 answer 120 views
1 answer 177 views
...