Search code examples
c#stringtrim

.TrimEnd seems to group parameters


I've got a string containing a processname like

string name = "firefox.exe", now I need to remove only the ".exe" part, so I get the processname without the ending. I tried to use

   Console.WriteLine("output: " + processName.TrimEnd('.','e','x','e'));

But for some reasons output seems to be "firefo" without the "x". Any idea how to get this solved in an easy and clean way?


Solution

  • You ask it to trim the characters ., e and x from the end, so it does that:

    firefox.exe
    firefox.ex
    firefox.e
    firefox.
    firefox
    firefo
    

    how to get this solved in an easy and clean way?

    Using Path.GetFileNameWithoutExtension().