lua-users home
lua-l archive

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


a="k"

n=3

b=""

for c = 1, n do b = b..a end

print(b)

 

From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On Behalf Of Chris Datfung
Sent: 18 April 2013 13:16
To: Lua mailing list
Subject: pad a string

 

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

**************************************************************************************** Note: If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. ****************************************************************************************