Add a String of Numbers and get a Total
Moderator: Neosoft Support
Add a String of Numbers and get a Total
Hi guys, is there an easy way to add a group of 16 numbers contained in a string together and get the total value. e.g. "0123456789123456"= "66" I have looked at Ronnies rtMidString and looping and adding with math action but not getting what I want - i.e. the total of all the numbers in the string. As always any help appreciated.
Re: Add a String of Numbers and get a Total
ajhunt:
Try this code ...
Works with any string length.
Assumes that every character in the string variable is a number ... if not, you can add a check to see if [thisCharValue] is in range 0 to 9.
Try this code ...
Code: Select all
SetVar "[theString]" "1234567890123456"
StrLen "[theString]" "[theStringLen]"
SetVar "[thisStringTotal]" "0"
Loop "1" "[theStringLen]" "[thisCharPos]"
SubStr "[theString]" "[thisCharPos]" "1" "[thisCharValue]"
Math "[thisCharValue]+[thisStringTotal]" "0" "[thisStringTotal]"
EndLoop
Assumes that every character in the string variable is a number ... if not, you can add a check to see if [thisCharValue] is in range 0 to 9.
Re: Add a String of Numbers and get a Total
Hi Gaev, many many thanks as always - a real champion to NeoBook. Looks easy when you know how lol. Best regards.