Hey Leonard,
Ha!. Gabe beat me to the punch by about an hour.
Gabe ⇢ My approach was almost exactly like yours, although I hadn’t bothered with the formatted output. Good job.
Okay, I’ll demonstrate once again why I like the Satimage.osax so much.
If you forget about the handlers there’s all of 4 lines of code.
(Remember — the script won’t work, unless the Satimage.osax has been installed!)
-Chris
------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2017/11/19 07:25
# dMod: 2017/11/19 07:30
# Appl: AppleScript + Satimage.osax
# Task: Extract values from text and sum them
# Libs: None
# Osax: Satimage.osax (MUST BE INSTALLED OR THE SCRIPT WON'T WORK!)
# Tags: @Applescript, @Script, @SIO, @Satimage.osax, @Extract, @Values, @Text, @Sum, @Them, @ccstone
------------------------------------------------------------------------------
set sourceText to "
BESTELLUNG AUFGEGEBEN
3. Oktober 2017
SUMME
EUR 20,40
BESTELLUNG AUFGEGEBEN
3. Oktober 2017
SUMME
EUR 21,40
BESTELLUNG AUFGEGEBEN
3. Oktober 2017
SUMME
EUR 22,40
BESTELLUNG AUFGEGEBEN
3. Oktober 2017
SUMME
EUR 23,40
"
set euroList to fndUsing("^SUMME\\nEUR (\\d+,\\d+)", "\\1", sourceText, true, true) of me
set euroList to cng(",", ".", euroList) of me
set theSum to format (sum of (statlist euroList)) into "€0.00"
------------------------------------------------------------------------------
--» HANDLERS
------------------------------------------------------------------------------
on cng(_find, _replace, _data)
change _find into _replace in _data with regexp without case sensitive
end cng
------------------------------------------------------------------------------
on fndUsing(_find, _capture, _data, _all, strRslt)
try
set findResult to find text _find in _data using _capture all occurrences _all ¬
string result strRslt with regexp without case sensitive
on error
false
end try
end fndUsing
------------------------------------------------------------------------------