string.gsub problem not able to replace string

I am trying to replace “.” with a “-” in a value that is returned from a sqlite database

I perform a normal 

for row in db:nrows(“SELECT * FROM checkmarks;”) do 

and then I try to convert the date to a string and then do the replace (in case the date is in the format 29.05.2018)  so that I later can send this value to the server in the correct MySQL date format:

The value in row.theServiceDate was stored as the value retrieved from a Date field in a MySQL database on our server.

local tempServiceDate = row.theServiceDate print("245 tempServiceDate: "..tempServiceDate) tempServiceDate = string.gsub(tempServiceDate,".","-") print("246 tempServiceDate: "..tempServiceDate)

The result I get looks like this:

"245 tempServiceDate: 08-05-2018" "246 tempServiceDate: ----------"

I then tried to convert it to a string first, but with the same result

 local theServiceDate = tostring(row.theServiceDate) print("247 theServiceDate: "..theServiceDate) theServiceDate = string.gsub(theServiceDate,".","-") print("248 theServiceDate: "..theServiceDate)

The result I get looks like this:

"247 theServiceDate: 08-05-2018" "248 theServiceDate: ----------"

How can I do a proper replace, without having to retrieve the day, month, year values in separate variables?

You are using a regex to match the entire string. Check the docs here:

https://docs.coronalabs.com/guide/data/luaString/index.html#character-classes

So, you want to match only the literal string “.”, use this:

“%.”

Eg:

local tempServiceDate = "08.05.2018" print(tempServiceDate) print(string.gsub(tempServiceDate,"%.","-"))

Btw, if you want to quickly test code, there is an online Lua sandbox (pure Lua, doesn’t support Corona API’s, of course):

https://www.lua.org/cgi-bin/demo

You are using a regex to match the entire string. Check the docs here:

https://docs.coronalabs.com/guide/data/luaString/index.html#character-classes

So, you want to match only the literal string “.”, use this:

“%.”

Eg:

local tempServiceDate = "08.05.2018" print(tempServiceDate) print(string.gsub(tempServiceDate,"%.","-"))

Btw, if you want to quickly test code, there is an online Lua sandbox (pure Lua, doesn’t support Corona API’s, of course):

https://www.lua.org/cgi-bin/demo