How can I perform multiple formatting to a string?
for e.g. doing in the following way doesn’t work.
var Id = (from p in db.vwIds.Where(p => p.OperationalNumber.Substring(p.OperationalNumber.IndexOf("-") + 1).TrimStart('0') == id)
group p by p.ID into g
select g.Key).ToList();
Can I not perform more than one actions on a string?
By doesn’t work I mean its not pulling Id’s from “vwIds”. When I hard-code the value of id to “001” and remove the “.TrimStart(‘0’) ” it pulls in the Ids, not otherwise.
Basically the id I am passing is a number without leading zeroes, e.g. “1”, “2”, “112” etc
And Ids present in vwIds are of format: “JEE – 001”, “Dee – 002” etc.
If you’re hard coding
idto “001” the it will never be equal to any ID that has had.TrimStart('0')called on it. Let’s assume for a moment thatp.OperationalNumber.IndexOf("-") + 1)evaluates to “001”. Calling “trimstart” on it will turn it into “1”. “1” is not equal to “001”, so it isn’t included.My guess is you need to call
.TrimStart('0')on ID as well, or better yet, parse both strings into numbers and then compare their numeric value, rather than their string value.