[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [StrongED] Regular Search and Replace on a key?



In message <50e1b4d819Lists@xxxxxxxxxxxxxx> you wrote:

> While we're on the subject, is there an easy way of doing the RiscOS <>
> Linux file path swap? i.e. exchange . and / in a URL?

Can you be more specific about what you want to do? We are presumably
talking about transforming text, not renaming files. Did you want
to convert a relative RISC OS filename (relative to the directory
containing the file containing the text) to the corresponding Linux
relative filename, so it can be used as a link in a webpage?

It may not be what you are after but this RiscLua function swaps
'.' with '/' in strings:

 slashdot = \(s)
    local dot,slash = '.','/'
    local swap = { [dot] = slash, [slash] = dot }
    => (s:gsub(dot,\(c) => swap[c] or c end)) end

It is an accident that dot is also the pattern that matches any
character ;). The extra parentheses cut out all the returned values
except the first; gsub (global substitution) returns not only the
converted string but also the number of matches, in this case the
length of the string, and you do not want the second of these.

This is a function I use in scripts for creating websites on my
hard disc, in a form ready to be ftp-ed up to a server.

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

-- 
To unsubscribe send a mail to StrongED+unsubscribe@xxxxxxxxxxxxxx