lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Is it though?  What's this commonly used for?

Assuming my string.gsub is already patched:


-- Case 1

local row = db:queryAssociativeRow('SELECT NAME,EMAIL FROM USERS WHERE ...')

print(row.NAME, row.EMAIL)
> John Doe	me@earth.com

print((string.gsub('Hi, %NAME! Is %EMAIL your email?', '%%(%w+)',row)))
> Hi, John Doe! Is me@earth.com your email?

-- Case 2

local logformat = '$Referer,$Accept,$Connection'

log:write((string.gsub('$Referer;$Accept-Encoding;$Connection', '$([%w_-]+)', request.headers)))
> http://localhost/index.html;gzip,deflate;keep-alive

-- Case 3

local accentTable = {
  ['á'] = 'a',
  ['à'] = 'a',
  ['ã'] = 'a',
  ['é'] = 'e',
  ['è'] = 'e',
  ['É'] = 'E',
  ['Ó'] = 'O',
  -- and so on...
}

print((string.gsub("Entre outras mil, És tu, Brasil, Ó Pátria amada! Dos filhos deste solo és mãe gentil, Pátria amada, Brasil!", '[áàãéèÉÓ]', accentTable))) > Entre outras mil, Es tu, Brasil, O Patria amada! Dos filhos deste solo es mae gentil, Patria amada, Brasil!




There are better ways to do all of them, but they are just examples anyway.

--rb