string library

Steve Yegge <[email protected]> Sun, 20 Mar 2005 23:01:21 -0800
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
Are there any plans to either create a string library for Nice,
or extend the functional (i.e. Haskell-prelude-ish) stuff to treat
strings as sequences?  Java's string support is a bit weak.

Related question:  what's the most succinct way of padding a
string out to a given width, with a given padding character?  I'm
more worried about brevity than performance in this case.

Here's one stab at it:

String pad(String s, char c, int w) {
    if (s.length() < w) for (int i : 1..w-s.length()) s += c; return s;
}

Works, but it gives me a warning about i being an unused local variable.
Is there a cleaner way to do it?

Cheers,

-steve


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click