Pastey Exorcism Tutorial: Acronym
- Posted by _tom (admin) Sep 30, 2019
include std/sequence.e include std/text.e include std/console.e function acronym( sequence phrase ) phrase = split( phrase ) phrase = trim( upper(phrase) ) for i=1 to length(phrase) do phrase[i] = phrase[i][1] end for return join(phrase, "") end function sequence s1 = "Portable network Graphics" display( acronym( s1 ) )
1. Comment by petelomax Oct 01, 2019
Minor variation
function acronym(string phrase) -- return upper(vslice(split(trim(phrase)),1)) -- Or, while the above style might appeal to some, -- it is harder to debug than the following, and -- in actual fact it would never run any faster. phrase = trim(phrase) sequence res = split(phrase) res = vslice(res,1) res = upper(res) return res end function ?acronym("Portable network Graphics") -- "PNG" -- Note that vslice() has been mopdified in 0.8.2+ to yield a string, when it can.
Also, Phix does not have a display() routine, and any include std/ lines should (ideally) be surrounded by --/* and --*/.