[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: pad a string
- From: Choonster TheMage <choonster.2010@...>
- Date: Thu, 18 Apr 2013 22:18:46 +1000
On Thu, Apr 18, 2013 at 10:15 PM, Chris Datfung <chris.datfung@gmail.com> wrote:
> Hi,
>
> I want to pad a string with itself n number of times, for example if n = 3
> and var="test" then var = var .. var .. var
>
> I tried with a for loop but get one too many combinations
>
>> a="k"
>> n=3
>> for c = 1, n-1 do a = a..a end
>> print(a)
> kkkk
>
> Is there a smarter way to implement this?
>
> Thanks,
> Chris
You want the string.rep function:
http://www.lua.org/manual/5.1/manual.html#pdf-string.rep
http://www.lua.org/manual/5.2/manual.html#pdf-string.rep