How to get filename after underscore

Hi Team,

I have a file with name benetton_12
I need to get output as 12 basically anything after that underscore

Hi @Rahul_S1

Got your point ,

Can you try this expression

Var1 = new System.IO.DirectoryInfo(“FolderPath”).GetFiles().Select(Function(file) Path.GetFileNameWithoutExtension(File.Name).Split("_"c).Last).ToArray()

This expression works dynamically

1 Like

Hi @nikhil.girish

Thanks I wanted the last syntax , the last syntax is alrdy built in code

Hi @Rahul_S1

You can try with Regular Expression

How about this expression

System.Text.RegularExpressions.Regex.Match(YourString,"(?<=_)\S.*").Tostring

image

Regards
Gokul

1 Like

Thanks guys @nikhil.girish @Gokul001

image

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.