Split list and remove duplicates

Hello,

I am trying to use a LINQ function to assign to variable. I have list that looks something like the list below:

25001\sample.json
25001\example.xlsx
25001\test.json
25002\example.xlsx
25002\sample.json
25002\test.xlsx

I want to split each item using “\” as the delimiter and keep only the first element. Using the input list above, I am trying to get the following output below:
25001
25002

Any help is appreciated.

Regards,
symilawr

Hi @symilawr

You can try with Regex expression ?

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

image

Regards
Gokul

HI @symilawr

You can try with split expression also

Split("25001\sample.json","\")(0)

image

Regards
Gokul

Hi,

Can you try the following expression?

resultList = yourList.Select(Function(s) s.Split("\"c).First).Distinct().ToList()

Regards,

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