ToolTimeGang
asked on
Is there a way I can trim trailing spaces in a linq query
Is there a way I can trim trailing spaces in a linq query?
query = From row In list
Where row.Working = inputData
In the above example, row.working = "No " and inputData = "No".
I know the best fix is to not allow data into the db with trailing spaces, but for now, I need to work with the data I have.
I have tried trimend and contains and neither worked. but maybe I am not using them correctly? I am kind of a newbie with linq.
thank you for helping me!
query = From row In list
Where row.Working = inputData
In the above example, row.working = "No " and inputData = "No".
I know the best fix is to not allow data into the db with trailing spaces, but for now, I need to work with the data I have.
I have tried trimend and contains and neither worked. but maybe I am not using them correctly? I am kind of a newbie with linq.
thank you for helping me!
Is your working field set as char(3) rather than varchar(3)?
Based on the code you show, I would expect:
query = From row In list
Where row.Working.TrimEnd().ToUpper() = inputData.TrimEnd().ToUpper()
ASKER
Private Function queryWorking(ByRef query As IEnumerable(Of ResponseTimeDto), _
list As List(Of ResponseTimeDto), _
inputData As String) As List(Of ResponseTimeDto)
query = From row In list
Where row.Working.TrimEnd().ToUpper() = inputData.TrimEnd().ToUpper()
Return query.ToList()
End Function
When I run this code, I get a nullreference exception on inputdata.trimend().touppeASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
When I run this code, I get a nullreference exceptionYou need to ensure that the strings you are trimming are not null. You might try:
query = From row In list
Where row.Working.TrimEnd().ToUpper() = IF(inputData Is Nothing, String.Empty, inputData).TrimEnd().ToUpper()
ASKER
That still doesn't work. I am going to stick with Exoas suggestion for now. Thanks for trying to help!
I am going to stick with Exoas suggestion for now.Huh?
ASKER
ok
ASKER
ok
ASKER
ok
ASKER
I actually had to fix it using RTrim instead.
Refer to this link:
http://social.msdn.microsoft.com/Forums/en-US/dd1c4669-0cee-4c62-a5c9-1e54eb32df2a/linq-to-entities-trimend
Refer to this link:
http://social.msdn.microsoft.com/Forums/en-US/dd1c4669-0cee-4c62-a5c9-1e54eb32df2a/linq-to-entities-trimend
ASKER
Other suggestions were not working for me. This one did work. not the best solution, but it works.