Skip to Content
0

Remove Leadind zeros from String

May 01 at 03:57 PM

22

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Dell Stinnett-Christy May 01 at 05:01 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Abhilash Kumar
May 01 at 05:05 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded