Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.apps > #2611

Search and Replace

Date 2012-01-08 13:52 +0000
From Gavin Wraith <gavin@wra1th.plus.com>
Message-ID <d9c35b4e52.wra1th@wra1th.plus.com> (permalink)
Organization Home
Subject Search and Replace
Newsgroups comp.sys.acorn.apps

Show all headers | View raw


> Is there an easy way to apply a series of search and replace strings
> to a piece of text, from a list or table?

Yes. Use StrongED and drag in a script like this, with the
replace table appropriately modified (presuming you have !lua
filerbooted).

  #! lua
  -- multiple search and replace
  local replace = { -- edit this table
  ["seperate"] = "separate";
  ["supercede"] = "supersede";
  ["kernal"] = "kernel";
  ["old rubbish"] = "snappy phrase";
  }
  -- search for string in square brackets, replace with
  -- string between equal sign and semicolon.
  local transform = \(x,y)
     for old,new in pairs(y) do
       x = x:gsub(old,new)
     end -- for
     => x
   end -- function
  local f = io.open(arg[1],"r")
  local s = f:read "*all"
  f:close()
  io.write(transform(s,replace))

-- 
Gavin Wraith (gavin@wra1th.plus.com)
Home page: http://www.wra1th.plus.com/

Back to comp.sys.acorn.apps | Previous | Next | Find similar | Unroll thread


Thread

Search and Replace Gavin Wraith <gavin@wra1th.plus.com> - 2012-01-08 13:52 +0000

csiph-web