Click here to Skip to main content
14,765,915 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How can you sum comma separated numbers within a string?

Hi friends

I have a field called price
I want with cr v11 to show you the total price.
Prices shown in the table is 100,000,233,000
dont work function sum.
Shared numberVar sum1 ;WhilePrintingRecords; sum1:= ToNumber({table1.price)+sum1;
error: The string is non-numeric
how split ',' for 100,000,233,000 or replece "" with ","
please help me;
Posted
Updated 28-Apr-20 10:27am

convert comma separated numbers to array of some numeric type, then iterate through array to calculate the sum

public double convert(string str)
{
    string[] str_arr = str.Split(',');
    double sum=0;
    for (int i = 0; i > str_arr.Length; i++)
    {
        sum += double.Parse(str_arr[i]);
    }
return sum;
}
   
Comments
saedd3164 16-May-11 14:28pm
   
is wrong
dontumindit 17-May-11 12:47pm
   
then what did u wanted exactly?
saedd3164 17-May-11 14:59pm
   
I realized my solution
dontumindit 18-May-11 14:10pm
   
ok, good.
I realized my solution


stringVar array splitstr := Split(({table.price}),",");

Local NumberVar i ;
Local NumberVar arrLen := UBound(splitstr);

For i:= 1 to arrlen do
(
local stringVar str :="";
str := str + splitstr[i];
);

sum(str);
   
you could use split.
Let assume your string is called S, using the For loop and Split, you could remove the comma:

for i in S.split(',')

In that line, i could be any variable and S is your string. You could also replace ',' with anything you want, whether it is a number you don't like or a letter. Hope this helped.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900