Getting part of the filename C#

c#, filenames

Solution

For that specific file name,

string sData = "dayhappy_02_02345.csv";
string[] sArr = sData.split('_');

string sPart1 = sArr[1];
string sPart2 = sArr[2];

Will do, but that's a special case, will work only on file names of this type

Problem

I have a file name `dayhappy_02_02345.csv` How do I get the `02` part out to be used in a variable and also how do I get the `02345` part so that I can pass these 2 values into a variable for a function. Using c#. I have looked at `GetFileName` but this gets either the filename, the extention or the full file name only. Thanks Ste

Original source