This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Replace . with ,
#1
Hi

I am struggling a bit to do a replacement inside a value. What I want to do is make a log of temperatures and write this as CSV to an FTP-server at an external PC. All this works fine, but when I open the CSV in Excel, then MS in their infinite wisdom has decided that numbers containing '.' should be automatically seen as a date. 

I am able to fix this myself in Excel, but in this case the users are not familiar with the use of computers, or any device connected to power, and so I must make it idiot-proof.

What I would like to do is to replace the '.' with a ',' in the value before adding it to the CSV. But I am not able to do this.

If I use string.gsub(), all characters in the value is replaced with ',', and I get values like ',,,,'. I tested a bit with string.find() to see how the '.' is read, and it seems to be some kind og 'magic character'? If I use the 'plain' parameter in string.find() I am able to find the '.'.

So, in short; how do I do this?
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
#2
Dot is a special symbol which means "any character". Add % before the dot and it will work:
Code:
value = value:gsub('%.', ',')
Reply
#3
(18.10.2021, 14:40)admin Wrote: Dot is a special symbol which means "any character". Add % before the dot and it will work:
Code:
value = value:gsub('%.', ',')

OK, thanx.
Will test this tomorrow morning when I am at the SL again.
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply
#4
(18.10.2021, 14:40)admin Wrote: Dot is a special symbol which means "any character". Add % before the dot and it will work:
Code:
value = value:gsub('%.', ',')

Worked like a charm.

Thanks for help, once again!
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply


Forum Jump: