?"\*0abc" -- expected: bc -- actual: abc |
Perhaps this isn't a bug, but it could make a padding function a lot simpler.
function pad(str, char, len) return str.."\*"..(len-#str)..char end ?pad("hello","h",6) -- helloh ?pad("hello","h",5) -- helloh -- second one should just be hello |
Hi @Einstein2:
I'm wondering if this might break some existing carts already making using of the \*
repeat command.
Your function could be though:
function pad(str, char, len) return sub(str.."\*"..(len-#str)..char,1,len) end cls() print(pad("apple","*",8)) ?"" ?"" ?"" APPLE*** |
Which will truncate not just the added characters but the string itself, giving you no string for zero length.
You're very welcome, @Einstein2 ! Try entering a negative value above for length and you get a funny result though. :)
Easily fixed.
function pad(str, char, len) return sub(str.."\*"..(len-#str)..char,1,max(0,len)) end |
1
Thanks @Einstein2 -- This is fixed for 0.2.5d
It might cause a little breakage, but I agree that ?"*0abc" should print "bc" and think it's worth changing.
[Please log in to post a comment]