开发者

How to trim in Linq to SQL?

I have a table like this: (can't change this)

id  value   other
-----------------------------
1   000033  sasdsa
2   000033  dasfgds
3   33      sadasdas
4   33      pdfsfsd
5   234543  posjfd

Can someone tell me how can I trim leading zeros with Linq?

I tryed this:

from t in table
where  (t.value.TrimStart('0')).Eq开发者_开发知识库uals("33")
select t

but it doesn't work :S


The 'value' field is obviously a string since it's retained the leading zeroes. I've not tried but can you not cast the value as an integer before doing the comparison? Something like:

from t in table
where (t => Convert.ToInt32(t) == 33)
select t

If you need to keep the value as a string, you could use string.EndsWith() but you might have problems with matching the correct 'value'.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜