• mike (unregistered) in reply to Peter
    Peter:
    Er - in what language is it a common idiom to have three open braces but only one close brace?

    Doh! Typo.

  • Joe Brewer (unregistered)

    Why would I want to copy this code to the clipboard ?

  • jtolar (unregistered)

    Contractor paid by the line?

  • (cs)

    PEOPLE GET PAID TO WRITE THIS???!!!

    Un-fucking-believable...

  • Frying Pan (unregistered)

    Not even a nested series of if statements I wonder if the coder was getting paided by the unit of code he/she wrote.

  • Consultant (unregistered) in reply to snoofle

    The kind who is making $150 / hour.

    Bwahahahaha.

  • Andy (unregistered) in reply to snoofle

    A computer being paid by the hour.

    HEYOOOOO

  • Alex P. (unregistered)

    I think a Lisper would just use the built-in format function, something like (format nil "~100,'0d" data).

  • Iv (unregistered)

    I don't get it :

       if (length >= 100) {
          NewData = Data.substring(0,length);
       }
    

    shouldn't it be NewData = Data.substring(0,100); instead ? There is a bug ! there is a bug !

  • Jerry Mannel (unregistered) in reply to snoofle

    May be Brian was a computer. Now he has crashed and is under a pile of junk

  • (cs)

    LINQ is your friend

    var foo = "123";
    var bar = String.Concat(String.Join(String.Empty,(from dummy in Enumerable.Range(0, 100 - foo.Length) select "0" as string).ToArray()), foo);
    
  • AdT (unregistered)

    Haskell:

    rightPad c n = take n . (++ repeat c)
    leftPad c n = reverse . rightPad c n . reverse

    Usage examples:

    leftPad '0' 10 (show $ 7 * 673) = "0000004711"
    
    leftPad (0,0) 5 [(1,2),(2,3),(3,5)] = [(0,0),(0,0),(1,2),(2,3),(3,5)] -- works with all lists, not just strings :)
    
    join $ map (leftPad ' ' 3) ["ABC","DE","F"] = "ABC DE  F"
  • Ouch! (unregistered) in reply to AdT
    AdT:
    Haskell:
    rightPad c n = take n . (++ repeat c)
    leftPad c n = reverse . rightPad c n . reverse

    Usage examples:

    leftPad '0' 10 (show $ 7 * 673) = "0000004711"
    
    leftPad (0,0) 5 [(1,2),(2,3),(3,5)] = [(0,0),(0,0),(1,2),(2,3),(3,5)] -- works with all lists, not just strings :)
    
    join $ map (leftPad ' ' 3) ["ABC","DE","F"] = "ABC DE  F"
    ghci> leftpad 0 10 [1 .. ]
    ^CInterrupted.
    

    Don't ignore infinite lists.

  • Just Some Guy (unregistered)

    Oh fer cryin out loud. :(

  • Jim Sangwine (unregistered)
    var length = Data.length; var NewData; if (length >= 100) { NewData = Data.substring(0,length);

    That is just fantastic.

    Whatever is wrong with good old direct assignment???

    if (length >= 100) NewData = Data;

  • mos (unregistered) in reply to snoofle

    hehe... double click LIPS and ctrl+c' it.

  • st0le (unregistered)

    I love the fact that the first time he/she uses the substring function he uses 'substring' he start at index 0...

    the following times, we see 'substring(length-x,...)'

    where 'length-x' is clearly zero...

  • Ichneumon (unregistered)

    This is clearly a job for recursion:

    string Pad100(string data)
    {
        if (data.GetLength() >= 100)
            return data;
        else
            return Pad100("0"+data);
    }
    
  • Bianca Milatinovici (unregistered)

    And for Data longer than 100 chars, it returns the exact data, without trimming it .. :))

  • James (unregistered)

    He missed "if length = 0" Ahh well.

Leave a comment on “Maximum Pad”

Log In or post as a guest

Replying to comment #:

« Return to Article