Ray_Sha1
(Ray Sha)
July 30, 2021, 8:03am
1
Hi,
I have a datatable with 1 columns called names
I want to use a LINQ query to filter out the value with same first name i.e. and write it in a new datatable.
Example Datatable:
NAMES
AA AA
AA Bb
AA Cc
New datatable:
Aa
Any Idea?
Thanks in advance.
Yoichi
(Yoichi)
July 30, 2021, 8:19am
2
Hi,
How about the following?
newDt = dt.AsEnumerable.Select(Function(r) r("Names").ToString.Split({" "c})(0)).Distinct().Select(Function(x) newDt.LoadDataRow({x},False)).CopyToDataTable()
Sequence.xaml (8.6 KB)
Regards,
Ray_Sha1
(Ray Sha)
July 30, 2021, 8:21am
3
Hi @Yoichi ,
Instead of split can we use starts with?
Because some names have space and some don’t. Firstname and last name is written together.
Thanks in advance
Yoichi
(Yoichi)
July 30, 2021, 8:25am
4
Hi,
StartsWith method needs argument to check it. Which string do you want to check? Only “AA”? or do you have list of name?
Regards,
Ray_Sha1
(Ray Sha)
July 30, 2021, 8:28am
5
@Yoichi ,
There’s just one column and no other list.
Yoichi
(Yoichi)
July 30, 2021, 8:34am
6
Hi,
Firstname and last name is written together.
Generally, it’s difficult to separate firstname and lastname if there are no separator. Is there any rule to find it? (ex. Lastname always starts with capital. etc)
Regards,
Ray_Sha1
(Ray Sha)
July 30, 2021, 8:41am
7
@Yoichi , nothing specific.
Well, thank you so much for the input.
1 Like
system
(system)
Closed
August 2, 2021, 8:42am
8
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.