[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Replacing substrings in a string
- From: David Given <dg@...>
- Date: Wed, 07 Sep 2005 21:42:19 +0100
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Philippe Lhoste wrote:
[...]
> IIRC, the original message was concerned only by the percent sign (or so
> I understood), so I addressed only this case.
Actually, I just mentioned % as an example; I wanted a generic solution.
[...]
>> I suggest that (not tested) :
>>
>> pattern = string.gsub(generatedPattern, "(%c)", "%1")
>> newString = string.gsub(oldString, pattern, replace)
[...]
> I think that the control characters are those below Ascii 32, not the
> chars listed above.
It's grotesque, but:
pattern = string.gsub(generatedPattern, "(.)", "%%%1")
newString = ...
...might just work. It is, however, an awful lot of work --- I hate to think
how many memory allocations are required to do that.
Will it always be the case that the above will be faster than any in-Lua
looping code, due to Lua's dispatch overheads?
- --
+- David Given --McQ-+ "If you're up against someone more intelligent
| dg@cowlark.com | than you are, do something insane and let him think
| (dg@tao-group.com) | himself to death." --- Pyanfar Chanur
+- www.cowlark.com --+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFDH1Cpf9E0noFvlzgRAhtRAJ429EG9sJb2tx8x49PJSUZaNaT4EgCg1cpk
igUe3mlAqTMIZuMDnMVtHmw=
=j9yq
-----END PGP SIGNATURE-----