[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Replacing substrings in a string
- From: David Given <dg@...>
- Date: Wed, 07 Sep 2005 21:42:19 +0100
-----BEGIN PGP SIGNED MESSAGE-----
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
| firstname.lastname@example.org | than you are, do something insane and let him think
| (email@example.com) | himself to death." --- Pyanfar Chanur
+- www.cowlark.com --+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
-----END PGP SIGNATURE-----