[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Cycling character strings
- From: Dirk Laurie <dirk.laurie@...>
- Date: Sat, 18 May 2013 20:59:14 +0200
2013/5/18 <meino.cramer@gmx.de>:
> suppose one have this string of letters:
>
> abcdefghijklmnopqstuvxyz
>
> in an array (table) and want to perform these steps:
I'll do two.
> 1. shift the string by a certain amount of characters cyclic
>
> abcderfghijklmnopqstuvxyz => ghijklmnopqstuvxyzabcderf
function string.shift(str,toleft)
return str:sub(toleft+1)..str.sub(1,toleft)
end
> print(("abcderfghijklmnopqstuvxyz"):shift(7))
ghijklmnopqstuvxyz
> 2. take off a character at a certain position
>
> ghijklmnopqstuvxyzabcderf +> g ijklmnopqstuvxyzabcderf
function string.replace(str,pos,byte)
return str:sub(1,pos-1)..byte..str:sub(pos+1)
end
You get the idea, I hope.