Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

i am having a Linq expression, i am using orderby for the linq. can you plz tell how can i trim the value of the column.

My Linq expression is:

C#
var distinctvalues = (from row in Employees
                                        select new
                                        {
                                           row.Address
                                        }).Distinct().ToList();


the values i have in the employee is

1) " 1290 rd"
2) "874 sc"

i want to trim the value. can you plz tell me how can i trim the value.
Posted
Updated 10-Mar-12 9:04am
v2

Replace

C#
row.Address


with

C#
row.Address.Trim()


(this is assuming row.Address is a string).
 
Share this answer
 
Comments
inayat basha 10-Mar-12 17:20pm    
ya tried it giving me the error
ekolis 10-Mar-12 17:21pm    
Really? What error did you get?
inayat basha 10-Mar-12 17:22pm    
"cannot assign method group to anonymous type property"
ekolis 10-Mar-12 17:23pm    
Did you forget the parentheses after Trim?
inayat basha 10-Mar-12 17:23pm    
invalid anonymous type member declarator
Easy:

C#
var distinctvalues = (from row in Employees
                                        select new
                                        {
                                           row.Address.Trim()
                                        }).Distinct().ToList();

I am assuming that row.Address is a string.
 
Share this answer
 
Comments
Clifford Nelson 11-Mar-12 18:56pm    
Have not heard anything back. Did it work?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900