StripChar() = "Extreme NIH"

« Return to Article
  • Mike Raiford 2004-06-08 15:03
    Actually, <br> <br>This *could* be a hold over from the VB5 days when there was no such thing as a replace function.
  • Jim Bolla 2004-06-08 15:19
    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 2004-06-08 15:48
    check out this function written by a Sr. Dev where I work, he could have user Replace(str,&quot;'&quot;,&quot;''&quot;) <br> <br>'Function: QuoteForFilter <br> 'Description: This function returns the passed string with single quote(') <br> 'characters replaced with two single quote characters. Prepares the <br> 'string to be used as part of a RowFilter expression. <br> 'For example: <br> ' QuoteForFilter(&quot;PIG'S FEET&quot;) returns &quot;PIG''S FEET&quot; <br> Private Function QuoteForFilter(ByVal criteria As String) As String <br> Dim alCharBuffer As New System.Collections.ArrayList(criteria.Length) <br> Dim c As Char <br> <br> For Each c In criteria <br> alCharBuffer.Add(c) <br> If c = &quot;'&quot;c Then <br> alCharBuffer.Add(&quot;'&quot;c) <br> End If <br> Next <br> Return New String(CType(alCharBuffer.ToArray(GetType(Char)), Char())) <br> End Function
  • FistyTheFerret 2004-06-09 00:05
    Although piss funny, I'm with Mike. <br> <br>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 2004-06-09 08:20
    The mobile JVM for WinCE we're using implements java 1.1 spec. How much NIH do you think we have _had_ to do...?!? <br> <br>Before you ask, I don't know why we're using Java on PocketPC either.
  • Eric 2004-06-09 09:39
    &quot;This *could* be a hold over from the VB5 days when there was no such thing as a replace function.&quot; <br> <br>It wasn't. The first version of this software was written in VB6 SP5.
  • Mike Raiford 2004-06-09 12:22
    &quot;It wasn't. The first version of this software was written in VB6 SP5&quot; <br> <br>Like I said.. it could be. Obviously, this was not the case in this instance. <br> <br>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 ;) <br> <br>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. <br> <br> <br> <br>
  • James 2004-07-20 04:55
    jesus h christ! or you could do something like: <br> <br>$somestring =~ s/[c]+//g; <br> <br>in a language with Perlish regular expressions, where c is the character to whack.
  • plugwash 2004-10-16 16:43
    modern languages have a huge number of builtins <br> <br>this does not mean that every coder knows every builtin of every language they use <br> <br>
  • Crusty 2005-11-27 19:30
    Anonymous:
    modern languages have a huge number of builtins
    <br>
    <br>this does not mean that every coder knows every builtin of every language they use
    <br>
    <br>
    <br>
    <br>
    That's what language/function references are for.<br>
    <br>
    One of the most reliable ways to produce WTFs is to code without a <span style="text-decoration: line-through;">net </span>manual.<br>
  • BPFH 2005-11-27 23:11
    We've got a boatload of code where I work that exhibits this
    quality.&nbsp; 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().<br>
    <br>
    CopyChars() is basically strncpy().<br>
  • FredSaw 2005-11-29 10:54
    <P>
    Anonymous:
    That's what language/function references are for.
    </P>
    <P>Okay, but you have to get your coffee and settle into your easy chair and read the reference from front to back.&nbsp; Either that or study all of the "What's new?" section of the documentation.&nbsp; You can't just go looking up new keywords by intuiting them.&nbsp; </P>
    <P>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.&nbsp; But because he's trying to remove a character, not swap it for something else, it never occurs to him to look for "replace".</P>
  • Otto 2005-11-29 13:51
    <P>That's a good theory, except that googling for "vb6 remove characters from string" gives you this as the first result: <A href="http://www.codeguru.com/vb/gen/vb_misc/text/article.php/c2739/">http://www.codeguru.com/vb/gen/vb_misc/text/article.php/c2739/</A></P>
    <P>Google. It's like the ultimate reference manual.</P>
  • tharpa 2010-10-01 08:57
    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 2012-05-10 05:38
    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.