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__

Attachment: lstringpad-help.pd
Description: application/puredata

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


_______________________________________________
[email protected] mailing list
UNSUBSCRIBE and account-management -> 
http://lists.puredata.info/listinfo/pd-list

Reply via email to