Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

extract substring after the first underscore

I need to remove the underscore and all characters before it in my filename. The syntax of the filename is as follows:

<username>_<NameofFile>_<InstructorName>_<ClassName>.xls  

I want to keep everything BUT the <username>_ part.
I tried using .Split as follows:

string newfilename = file.Split('_')[1];

but that dropped everything and only kept <NameOfFile>.
How could this be achieved?

like image 391
MasterOfStupidQuestions Avatar asked Dec 11 '22 07:12

MasterOfStupidQuestions


1 Answers

string newfilename = file.Substring(file.IndexOf('_') + 1);
like image 111
AlexD Avatar answered Dec 25 '22 19:12

AlexD