Re: string library

Bryn Keller <[email protected]> Mon, 21 Mar 2005 10:01:39 -0800
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
Steve Yegge wrote:

>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.
>  
>
That would be great. People sometimes add string functions as they have 
time, but as far as I know there's no unified plan for this.

>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?
>  
>
How about this?

String pad(String s, char c, int w) {
  if (s.length < w)
    return s + new String(new char[w - s.length()].fill(int i => c));
  else
    return s;
}

Bryn


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