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


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

Search and Replace

Started byGavin Wraith <gavin@wra1th.plus.com>
First post2012-01-08 13:52 +0000
Last post2012-01-08 13:52 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.sys.acorn.apps


Contents

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

#2611 — Search and Replace

FromGavin Wraith <gavin@wra1th.plus.com>
Date2012-01-08 13:52 +0000
SubjectSearch and Replace
Message-ID<d9c35b4e52.wra1th@wra1th.plus.com>
> 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/

[toc] | [standalone]


Back to top | Article view | comp.sys.acorn.apps


csiph-web