Skip to Content
avatar image
Former Member

Remove Leadind zeros from String

The data looks like this:

000234R

001034S

011009R

000045D

It is coming from a varchar field in the database and needs to appear on the report like this:

234R

1034S

11009R

45D

I am not having luck removing the preceding 0’s

Help

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • May 01 at 05:01 PM

    Try a formula something like this:

    StringVar result := '';
    NumberVar i := 1;
    booleanVar done := false;
    While i <= len({MyTable.MyField}) and not done do (
        if {MyTable.MyField}[i] = 0 then
          i := i + 1
        else (
          result := right({MyTable.MyField}, len({MyTable.MyField} - i + 1;    
        done := result <> '';
    );
    result

    You may have to play with the semi-colons that end the lines to get the formulas to save correctly, but this should get you what you need.

    -Dell

    Add comment
    10|10000 characters needed characters exceeded

  • May 01 at 05:05 PM

    Hi Monica,

    Here's another formula :

    local stringvar s := {string_field}; //Replace string_field with the correct database field
    local numbervar i;
    local stringvar s2;
    for i := 1 to len(s) do
    (
        if s[i] = '0' then
            s2 := s[i+1 to len(s)]
        else
        (
            s2 := s;
            exit for;
            s;
        );
    );
    s2;

    -Abhilash

    Add comment
    10|10000 characters needed characters exceeded