Link to home
Start Free TrialLog in
Avatar of Oneill0003
Oneill0003

asked on

Summing Field and Counting Number of Digits

I’m using the following formula to get only the numbers of an address example:
4301 Robinson -----4301
356 street apart:234 -----356234

local stringvar result;
local numbervar i;

for i := 1 to length({table.address})
do
(
    if {table.address}[i] in ["0" to "9"] then
        result := result & {address.address}[i];
);

result

What I’m trying to accomplish now is to have two fields next to this one. The first field will give me that sum of the digits and the second field will give me the total number of digits on that field. Example:

From 4301 Robinson I get 4301

JustDigits      SumOfDigits        #Digits
4301                  8                       4

From 356 Hillboro Suit 234 I get 356234 so….

JustDigits      SumOfDigits        #Digits
356234                 23                   6

Any ideas?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of bdreed35
bdreed35
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike McCracken
Mike McCracken

Looks good.

mlmcc
Avatar of Oneill0003

ASKER

Thanks bdreed35 it worked beautiful, one last thing, can you give me a brief explanation of what you are doing on your code just for references and for my own benefit?

Thanks a lot!
Sure.

//Formula1 - the original one.
This formula loops through the field and builds the result formula with just the numbers from the address field.
It also totals the values of those digits and stores them in a variable.
It the returns the string of the digits.

//@SumOfDigits
This formula just displays the variable that was totaled in formula 1.

//@NumberofDigits
Thie formula returns the length of the number string that was built in formula 1.
Thanks!
No problem.