Matching id with ignoring 1 character

hi. i want to match id from dt1 and dt2
i want to match them while ignoring 1 character in the id.
the dt1 ids have (‘) in the end.
the reason why i put (’) in the id in dt1 cause the excel auto change the ids after my first output.


We can achieve this using TrimEnd method, as the following, for example.

newDt = dt1.AsEnumerable.Where(Function(r) dt2.AsEnumerable.Any(Function(r2) r2("id").ToString=r("id").ToString.TrimEnd("'"c))).CopyToDataTable


will this remove permanent the (‘) in the dt1?
i need the (’) in the whole process.

this is my way of comparing ids
findrow = MSMEDT.AsEnumerable.Where(Function(x) x(3).ToString.Equals(currentrow(7).ToString)).FirstOrDefault()

Nope, it just evaluates string which is removed ' character. Data isn’t updated.

findrow = MSMEDT.AsEnumerable.Where(Function(x) x(3).ToString.Equals(currentrow(7).ToString)).FirstOrDefault()

Which is dt1 you said in the first post? (MSMEDT or datatable for currentrow?)


the currentrow is the one the have special character


All right. Can you try the following expression?

findrow = MSMEDT.AsEnumerable.Where(Function(x) x(3).ToString.Equals(currentrow(7).ToString.TrimEnd("'"c)).FirstOrDefault()


hi. it works. but i wonder why other ids still can’t match
those id that i highlighted matched but the ids on the top can’t match.

i manually checked the dt1 and dt2 and both ids are in there.


Can you share actual data?


im sorry it’s confidential.

the dt1 is .csv and the dt2 is .xlsx

but i manually checked both files. the ids are there. :frowning:

im having a hard time. cause some of my process is matching id. i’ve been stock in this issue since last week huhu.


For now, can you export worksheet of dt2 to csv file, then compare both record using text editor?
There might be something diffrence such as whitespace etc.


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