• Mike Raiford (unregistered)

    Actually,

    This could be a hold over from the VB5 days when there was no such thing as a replace function.

  • Jim Bolla (unregistered)

    Even still, they could've replaced the implemenation of the function to just use Replace, even if they wanted to leave the method in there.

  • David Burton (unregistered)

    check out this function written by a Sr. Dev where I work, he could have user Replace(str,"'","''")

    'Function: QuoteForFilter
    'Description: This function returns the passed string with single quote(')
    'characters replaced with two single quote characters. Prepares the
    'string to be used as part of a RowFilter expression.
    'For example:
    ' QuoteForFilter("PIG'S FEET") returns "PIG''S FEET"
    Private Function QuoteForFilter(ByVal criteria As String) As String
    Dim alCharBuffer As New System.Collections.ArrayList(criteria.Length)
    Dim c As Char

    For Each c In criteria
    alCharBuffer.Add(c)
    If c = "'"c Then
    alCharBuffer.Add("'"c)
    End If
    Next
    Return New String(CType(alCharBuffer.ToArray(GetType(Char)), Char()))
    End Function

  • FistyTheFerret (unregistered)

    Although piss funny, I'm with Mike.

    After developing a whole lotta shit in j1.4 I find out that the client is still on 1.3 (yes, I believed them when they said 1.4). As a result I had to write my own split and replace functions.

  • Richard (unregistered)

    The mobile JVM for WinCE we're using implements java 1.1 spec. How much NIH do you think we have had to do...?!?

    Before you ask, I don't know why we're using Java on PocketPC either.

  • Eric (unregistered)

    "This could be a hold over from the VB5 days when there was no such thing as a replace function."

    It wasn't. The first version of this software was written in VB6 SP5.

  • Mike Raiford (unregistered)

    "It wasn't. The first version of this software was written in VB6 SP5"

    Like I said.. it could be. Obviously, this was not the case in this instance.

    Heh, I remember how relieved I was when I found out VB6 had a replace function. That meant I could rip out the several dozen instances of the function from our software ;)

    Why someone would ever want to roll their own on something like this in VB is incredible. This is slower (and obviously, more complicated) than just using Replace.



  • James (unregistered)

    jesus h christ! or you could do something like:

    $somestring =~ s/[c]+//g;

    in a language with Perlish regular expressions, where c is the character to whack.

  • plugwash (unregistered)

    modern languages have a huge number of builtins

    this does not mean that every coder knows every builtin of every language they use

  • Crusty (unregistered) in reply to plugwash
    Anonymous:
    modern languages have a huge number of builtins

    this does not mean that every coder knows every builtin of every language they use



    That's what language/function references are for.

    One of the most reliable ways to produce WTFs is to code without a net manual.
  • (cs)

    We've got a boatload of code where I work that exhibits this quality.  I stripped a good deal of it out a couple of years ago, but our most persistent offender (used in far too many places to remove) is CopyChars().

    CopyChars() is basically strncpy().

  • (cs) in reply to Crusty

    Anonymous:
    That's what language/function references are for.

    Okay, but you have to get your coffee and settle into your easy chair and read the reference from front to back.  Either that or study all of the "What's new?" section of the documentation.  You can't just go looking up new keywords by intuiting them. 

    Imagine our author above, moving from VB5 to VB6 and hoping they've added a character removal routine, so he does a search on "stripChar", "charStrip", "charRemove", "stringRemove", "charDelete", and any other targets he can think of that would describe removing a character from a string.  But because he's trying to remove a character, not swap it for something else, it never occurs to him to look for "replace".

  • (cs) in reply to FredSaw

    That's a good theory, except that googling for "vb6 remove characters from string" gives you this as the first result: http://www.codeguru.com/vb/gen/vb_misc/text/article.php/c2739/

    Google. It's like the ultimate reference manual.

  • (cs) in reply to Otto
    Otto:
    That's a good theory, except that googling for "vb6 remove characters from string" gives you this as the first result: http://www.codeguru.com/vb/gen/vb_misc/text/article.php/c2739/ Google. It's like the ultimate reference manual.

    I wonder if he wrote his solution faster than you could implement something you found via a search engine.

  • Fausto (unregistered)

    Reinventing the wheels isn't necessarily a bad thing to do.

    In some languages, like AS3, building your own version of built-in methods can be very useful, especially if you're looking for soem performance improvements.

    A good example of this would be to inline your own version of Math.abs() or pretty much anything of the Math class.

    Not having to call the method from an external class and doing some improvements (like building some bitwise hell) can result in a method that returns the same than the built-in one, but that will also run hundreds (and sometimes thousands) of times faster.

Leave a comment on “StripChar() = "Extreme NIH"”

Log In or post as a guest

Replying to comment #:

« Return to Article