I need to do a sum of individual numbers from a string. One point of observation is that the string have different lengths. For instance:
e.g.:1) variable = “123456789” I need to sum 1+2+3+4+5+6+7+8+9
e.g.: 2) variable = “1000232323213” I need to sum 1+0+0+0+2+3+2+3+2+3+2+1+3
** As variable field is a result of a formule the lengths can be differents.
Welcome to the forum @eduardoam.
My suggestion is to use the RegEx Extractor node to extract the digits. After that, some basic manipulation gives you the sum:
Thank you very much for your quick answer!!
I’ve tried to download the workflow, but it is showing a message error:
First show me a message regarding to “missing node extension”
Second one, when I click on Yes option to install, it is showing a message that there are “no suitable extension found”
Do you know what I nedd to do here?
The RegEx extractor is not a “standard” KNIME node. You need to install the extension Palladian for KNIME from the an update site. See the link. And add the link to your KNIME - File - Preferences - Install/Update / Available Software sites.
That’s right, Regex Extractor works very fine with it…
I created a table with some examples as string column. If you have other type, will works too.
Then I set Regex as “\d” (a digit) and the output as rows to split it into rows.
After that, just use the groupby node to set the first example number as flag and the output to sum all rows.
Also, you could do it with some steps more (create variables, make some calcs for each value, create a chunk loop to validate row-by-row and make some calc to sum each value to a total variable… more work to do, but you’ll have the same result.
Something like this:
Looking row by row with chunk loop, then, split number by number using substring function and variables to change the position and save as a row result until the loop end and then, using a groupby node to sum all results… more complex, but it works.
KNIME_project_string_count.knwf (92.3 KB)
Thank you very much for your help, now it is working.
Thank you very much for your help.
Your workflow is exactly what I need, using a dynamic length.
I’m happy to know about it… good luck!
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.