I have file name which look like
Directory\name-secondName-blabla.txt
If I using string .split my code need to know the separator I am using,
But if in some day I will replace the separator my code will break
Is the any build in way to split to get the following result?
Directory
name
secondNmae
blabla
txt
Thanks
Edit My question is more general than just split file name, is splitting string in general
The best way to split a filename is to use
System.IO.PathYou’re not clear about what to do with
directory1\directory2\,but in general you should use this static class to find the path, name and suffix parts.
After that you will need
String.Split()to handle the-separators, you’ll just have to make the separator(s) a config setting.