[PD] string padding
Frank Barknecht
fbar at footils.org
Sun Dec 16 23:06:51 CET 2007
Hallo,
Andy Graybeal hat gesagt: // Andy Graybeal wrote:
> i'd like to pad a string... say for instance i want to pad the string
> "andy" and "ian" to be able to have a total of 10 characters, and the
> padding character will be an underscore. so the end result would add 6
> underscores to the string "andy" and seven underscores to the string
> "ian":
> "andy______"
> "ian_______"
You may need to find some external that will give you the length of
a symbol. Then substract that from your desired total length, make a
list of that length with your symbol and use [list-l2s] from list-abs
to build a single symbol out of your original string and the padding.
Or just install pdlua and use attached lua-external. Once you've
install pdlua, you can do all kinds of string/symbol processing using
Lua's string library easily.
Ciao
--
Frank Barknecht _ ______footils.org__
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lstringpad-help.pd
Type: application/puredata
Size: 430 bytes
Desc: not available
URL: <http://lists.puredata.info/pipermail/pd-list/attachments/20071216/30c2cd27/attachment.bin>
-------------- next part --------------
-- Written by Frank Barknecht in 2007, use however you like.
local M = pd.Class:new():register("lstringpad")
function M:initialize(name, atoms)
self.inlets = 2
self.outlets = 1
self.padlen = atoms[1] or 0
self.pad = atoms[2] or ""
return true
end
function M:in_1_symbol(s)
local res = s .. string.rep(self.pad, self.padlen - s:len())
self:outlet(1, "symbol", {res})
end
function M:in_2_float(f)
self.padlen = f
end
function M:in_2_symbol(s)
self.pad = s
end
More information about the Pd-list
mailing list