locked
Query Expression help RRS feed

  • Question

  • Hi everyone.

    On the account entity we have a custom field called ap_customergroup. This is a string field and contains numeric values. Problem with this field is that I want to remove the leading zeros. For e.g. 00041230. should be 41230


    I want to compare this field with another custom entity field (int).

    I have composed this query expression and it only works when the value exactly matches. I want the custom entity field to match with the account field even if there are leading zeros.


    QueryExpression query = new QueryExpression("account");
                query.ColumnSet = new ColumnSet(true);
                
                 if (entity.Attributes.Contains("ap_customergroupnumber"))
                {
                query.Criteria.AddCondition("ap_customergroup", ConditionOperator.Equal,      Convert.ToString(entity["ap_customergroupnumber"]));

               //query.Criteria.AddCondition(("ap_customergroup").TrimStart('0'), ConditionOperator.Equal, Convert.ToString(entity["ap_customergroupnumber"])); DOESN'T WORK.

               }

    Can anyone help?



    Friday, July 19, 2013 8:46 AM

All replies

  • Try this

    String s ="00000584000004000".TrimStart(new Char[] { '0' } );
    // s = "584000004000"


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Friday, July 19, 2013 9:19 AM
  • Try this

    String s ="00000584000004000".TrimStart(new Char[] { '0' } );
    // s = "584000004000"


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Thanks and Regards, Mohammad Yusuf Ansari http://microxrm.blogspot.in

    Your code will work, but you don't need to specify the char array since the TimStart method accepts a params char[] array. The following code will also work:

    string s = "00000584000004000";
    string noLeadingZeros = s.TrimStart('0');

    • Proposed as answer by Roshan Mehta Friday, July 19, 2013 10:59 AM
    Friday, July 19, 2013 10:59 AM