0

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?

dehner
  • 47
  • 1
  • 8
  • 1
    [FileName without extension](http://msdn.microsoft.com/en-us/library/system.io.path.getfilenamewithoutextension%28v=vs.110%29.aspx) – Sayse Dec 19 '14 at 10:32

1 Answers1

5

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().

CodeCaster
  • 147,647
  • 23
  • 218
  • 272