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


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

Search and Replace

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!Xl.tags.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!local2.nntp.ams.giganews.com!nntp.brightview.co.uk!news.brightview.co.uk.POSTED!not-for-mail
NNTP-Posting-Date Sun, 08 Jan 2012 07:52:40 -0600
Date Sun, 08 Jan 2012 13:52:30 GMT
From Gavin Wraith <gavin@wra1th.plus.com>
Message-ID <d9c35b4e52.wra1th@wra1th.plus.com> (permalink)
Organization Home
User-Agent Messenger-Pro/1.00c (MsgServe/1.00a) (RISC-OS/5.16) NewsHound/v1.50-32
Subject Search and Replace
Newsgroups comp.sys.acorn.apps
Lines 31
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-EEQGr7glGq8YcKeBl2vjuFrjBZ/scsmUbSwfpmUzedFk/hmHGnCu3Bk2YNCZ483lRHnsSMcaj6pepOo!oEOOJBGDGdHbuB1S6rVTnmQ0WMFKBK/wbCl7KKujrth2NFMLZ5ml/OTSgwKAB9N1dxoMylYq38kS!UtTM
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 1767
Xref x330-a1.tempe.blueboxinc.net comp.sys.acorn.apps:2611

Show key headers only | 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