lua-users home
lua-l archive

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

2013/5/18  <>:

> 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)

> print(("abcderfghijklmnopqstuvxyz"):shift(7))

>     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)

You get the idea, I hope.