Help pull a substring out of a string from a datatable and add to a new datatable

Hello all,

I saw some other articles on a similar problem but nothing is quite fitting my issue.

I have a folder, the folder path is known let’s say C:\Desktop\Test1

I have a process to read all the files within that folder and add them to a string array- “filepaths”. File structure is 12345&4321.pdf.

I want to get the numbers between the “test1” and “&” - so in the example of C:\Desktop\Test1\12345&4321.pdf i need the “12345”

So I have a for each item in filepaths and i tried to do the regex match and then add those values to a datatable i then have it write the datatable into a csv but nothing is coming out!!!

If anyone knows a better way or a different way please help!

Hi,

How about the following expression?

System.Text.RegularExpressions.Regex.Match(System.IO.Path.GetFileName(yourFilePath),"\d+(?=&)").Value

Regards,

Hi,

FYI, the following will probably work for your full requirement.

Regards,

Thanks so much for showing that out - I see the error I was making.

Much appreciated

1 Like

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