Search code examples
coldfusioncoldfusion-9

Is there a way to add numeric values together in a string without looping?


I have a string say: '212'. This string is dynamically generated.

Is there a way to add these numbers together without looping?

If needed, I will loop and add the values; but after researching the Adobe Docs I wanted to see if there was a better way.

Thank you


Solution

  • Sure.. just for fun.

    digits = 212;
    sum = arraySum(listToArray(digits, ""));
    writeOutput(sum);
    

    Run script above: http://trycf.com/gist/3677b4e7d17d4fbac37d/acf