String manipulation for a part of sentence

I want to extract/check if key is within the directory of file.

For example I have list of directories as below:
\Users\Documents\C1PN-SA-17 TORONTO
\Users\Documents\C1PN-SA-129_TOKYO
\Users\Documents\C1PN-SA-1-INDIA

What to find: C1PN-SA-1
Objective: To find the exact match of key and choose that file (\Users\Documents\C1PN-SA-1-INDIA)

What have I did was doing the .Contains but all directories will return True.

You can try to make the contains more strict by: "C1PN-SA-1-"

as an alternate we can also shift to regex ismatch
grafik
[CheatSheet] - System.Text.RegularExpressions | RegEx - News / Tutorials - UiPath Community Forum

Hi,

Hope the following expression will help you.

arrInput.Where(Function(s) System.Text.RegularExpressions.Regex.IsMatch(System.IO.Path.GetFileName(s),"C1PN-SA-1\D")).ToArray()

Sample
Sample20240513-1.zip (2.8 KB)

Regards,

this one is a bit strict, i want it to by dynamic to cater the others possible scenario

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