With gsub()
?
€ /bin/lua
Lua 5.1.5 Copyright (C) 1994-2012 Lua.org, PUC-Rio
> str = "skylift valkyrie2 airbus hunter adder bus armytanker armytrailer armytrailer2 baletrailer boattrailer"
> do local text, count = str:gsub('%w+', function(match) return(match):upper() end) print(text, count) end
SKYLIFT VALKYRIE2 AIRBUS HUNTER ADDER BUS ARMYTANKER ARMYTRAILER ARMYTRAILER2 BALETRAILER BOATTRAILER 11
You are free to do what you want in the function in gsub()
.
For example table.insert(gstab, match)
> gstab = {}
> gsfunc = function(match) local match = match:sub(1, 1):upper() .. match:sub(2, -1) table.insert(gstab, match) return(match) end
> str:gsub('%w+', gsfunc)
> print(table.concat(gstab, '\n'))
Skylift
Valkyrie2
Airbus
Hunter
Adder
Bus
Armytanker
Armytrailer
Armytrailer2
Baletrailer
Boattrailer