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.

Find and Replace script
#7
(10.01.2020, 14:06)admin Wrote: You can fix encoding of your ESF here: https://openrb.com/convert/
Yea, but as I recall, that one does not work with large files. 
It is not a big thing, we are normally not using the special characters, but sometimes they are there.. :-)

For anyone that might need the same function, Here is the working code, a little cleaned up:
Code:
finn = 'Text to find'
replace = 'Text to add'
kriterie = 'Filter criteria'

liste = db:getall('SELECT name, id FROM objects WHERE name LIKE "%'.. kriterie .. '%"')

for _, name in ipairs(liste) do
  navn = name.name
  newName = string.gsub(navn, finn, replace)
  log(navn, newName)
  db:update('objects', { name = newName }, { id = name.id })
end
log('FINISHED')

script.disable(_SCRIPTNAME)
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply


Messages In This Thread
Find and Replace script - by Trond Hoyem - 10.01.2020, 10:52
RE: Find and Replace script - by admin - 10.01.2020, 12:48
RE: Find and Replace script - by Trond Hoyem - 10.01.2020, 13:06
RE: Find and Replace script - by admin - 10.01.2020, 13:35
RE: Find and Replace script - by Trond Hoyem - 10.01.2020, 13:53
RE: Find and Replace script - by admin - 10.01.2020, 14:06
RE: Find and Replace script - by Trond Hoyem - 10.01.2020, 14:10

Forum Jump: