aboutsummaryrefslogtreecommitdiff
path: root/challenge-001/paulo-custodio/lua/ch-1.lua
blob: c38dca5246c6fb30eddc6483ae569c28dd53c9e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/usr/bin/env lua

--[[
Challenge 001

Challenge #1
Write a script to replace the character ‘e’ with ‘E’ in the string
‘Perl Weekly Challenge’. Also print the number of times the character ‘e’
is found in the string.
--]]

count = 0
words = {}
for i=1, #arg do
    word, n = string.gsub(arg[i], "e", "E");
    table.insert(words, word)
    count = count+n
end

io.write(count, " ", table.concat(words, " "), "\n")