rory.ap
rory.ap

Reputation: 35318

Is there a file extension separator character constant in .NET?

Is there some way to get the character constant in MS Windows that is used to separate a file name from its extension (much like you can use Path.DirectorySeparatorChar to obtain the platform-specfic directory path separator)? I know it's been . since the beginning of time and probably always will be, but it doesn't feel right to hard-code it everywhere or make my own constant.

Upvotes: 3

Views: 1980

Answers (2)

JohnT
JohnT

Reputation: 426

In many cases you can use Path.ChangeExtension(), which allows you to omit the period from the second argument and supplies it automatically, to avoid making it part of your own constant.

If you really wanted to get the system character, you could examine the output of Path.ChangeExtension() and see what was inserted.

But I agree with the previous answer that assuming it will always be period is quite safe.

Upvotes: 1

Sriram Sakthivel
Sriram Sakthivel

Reputation: 73502

I can see inside the .Net framework even microsoft hardcodes . character as seperator, I don't think anything wrong in ourself hardcoding it.

Looking through the source I guess there is no platform specific method to get the extension seperator(atleast to my knowledge).

Upvotes: 5

Related Questions