[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Replacements of String Characters in LUA by using the Character Indexes
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sat, 11 Mar 2017 08:09:12 +0200
[Excuse the top-post, forgot to pack a mouse in my laptop bag.)
The pattern () captures a position and gsub allows a user-specified
function as replacement.
You will also need to capture the characters themselves.
pat = '()(.)'
repl = function(k,c)
if k>=2 and k<=4 then return ('AUSTRALIA'):sub(k+2,k+2)
else return c
2017-03-11 7:42 GMT+02:00 Naushad Mujawar <firstname.lastname@example.org>:
> Dear Team,
> I am beginner in LUA Programming.
> I wanted to write a LUA program to replace the some characters of the string
> by using the index places of those characters.
> e.g. If String is "INDIA", then I wanted to replace the characters of the
> string at indexes 2, 3 & 4 with the characters with indexes 4,5 & 6 of other
> string " AUSTRALIA" so that my Output String will be " ITRAA".
> But I am not able to find any standard LUA Function to replace the
> characters of the string by using character indexes.
> Please provide me with any reference guide or any standard lua function to
> replace the strings in lua.
> Thanks and Regards,
> Naushad Mujawar