• (cs) in reply to Addison
    Addison:
    At least he put it in a function.
    Looks more like a func to me.
  • (cs)

    This is actually pretty clean, compared to some of my first coding attempts (which were in kindergarten)...

  • (cs) in reply to Arlen Cuss
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
  • bobbytables (unregistered)

    How did I know this was going to be VB?

  • ricecake (unregistered) in reply to SenTree
    SenTree:
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.
  • (cs) in reply to Trondster
    Trondster:
    Naw - it's much too readable.
    I can see some premature optimisations needed:
    dim offset as integer
    offset = 0
    For i = 0 To 12
      Select Case i
        Case 0,4,8
          if i = 8
            formattedPhoneNumber.Append("-")
          else
            formattedPhoneNumber.Append(Chr(40+offset))
          end if
          offset = offset + 1 
        Case Else
          formattedPhoneNumber.Append(cleanPhoneNumber.Chars(i-offset))
      End Select
    Next
    
  • (cs) in reply to BK

    Compile error: formattedComment not defined

    Error: ToString (method) is used like a property

    :-)

  • (cs) in reply to campkev

    JPSoft batch:

    @echo off
    do i = 0 to 2
      switch %i
      case 0
        echos W
      case 1
        echos T
      case 2
        echo F
      endswitch
    enddo
  • (cs) in reply to Pim
    Pim:
    I want to see what the StripNonNumericCharacters function looks like!
    My guess would be something like this...

    Public Function StripNonNumericCharacters(ByVal sOrginalPhoneNumber as String) as String

    DIM sCleanPhoneNumber
    
    sCleanPhoneNumber = Replace(sOrginalPhoneNumber,"A","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"B","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"C","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"D","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"E","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"F","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"G","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"H","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"I","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"J","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"K","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"L","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"M","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"N","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"O","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"P","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"Q","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"R","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"S","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"T","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"U","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"V","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"W","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"X","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"Y","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"Z","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"a","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"b","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"c","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"d","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"e","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"f","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"g","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"h","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"i","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"j","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"k","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"l","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"m","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"n","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"o","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"p","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"q","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"r","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"s","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"t","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"u","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"v","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"w","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"x","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"y","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"z","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"`","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"~","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"!","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"@","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"#","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"$","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"%","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"^","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"&","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"*","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"(","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,")","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"_","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"-","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"+","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"=[","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"]","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"\","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"{","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"}","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"|","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,";","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,";","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"""","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"'","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,",.","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"/","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"<","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,">","")
    sCleanPhoneNumber = Replace(sCleanPhoneNumber,"?","")
    
    return sCleanPhoneNumber
    

    End Function

  • (cs) in reply to ricecake
    ricecake:
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.
    Yes, the English language has strange grammar policies!
  • (cs) in reply to ricecake
    ricecake:
    SenTree:
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.

    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).

  • juju (unregistered) in reply to some schmoe
    some schmoe:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
    Where does it do that? I only see a check for length = 0, otherwise it assumes all the characters are there. So if cleanPhoneNumber comes back with only 9 chars or less, it will blow up.

    Indeed it will blow up. Maybe the function that returns the 'clean' phone number returns an empty string if the number is not in the correct format to begin with. We can only hope!

  • Right tool for the right job (unregistered)

    I use for loops for everything! I use for loops for everything! I use for loops for everything! I use for loops for everything!

  • (cs)

    But my phone numbers are +44 (20) 7555-1234 and +881 (7) 5555-1234 !

    How will I be able to enter them now?

  • Anonymous (unregistered) in reply to Vollhorst
    Vollhorst:
                For i = 0 To 12
    
                Select Case i
                    Case 0
                    Case 1
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(1))
                    Case 2
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(2))
                    Case 3
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(3))
                    Case 4
                    Case 5
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(5))
                    Case 6
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(6))
                    Case 7
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(7))
                    Case 8
                    Case 9
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(9))
                    Case 10
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(10))
                    Case 11
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(11))
                    Case 12
                        unformattedPhoneNumber.Append(uncleanPhoneNumber.Chars(12))
    
                End Select
    
            Next
    
    Obvious, isn't it?

    Clear as water...

  • (cs) in reply to pscs
    pscs:
    ricecake:
    SenTree:
    Arlen Cuss:
    'i' before 'e', except after 'c' ...
    weird ...
    Or sounding like 'a' as in "neighbor" or "weigh". Not the most leisurely of rhymes. I think I'm going to have a seizure.

    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).

    While I agree with you that the rule is almost useless, some of your examples are kind of WTF themselves. The rule is only meant for situations where the i and the e make a single sound. In science, society, deity and seeing, the i and the e are part of different syllables. Also, eider is Swedish, so you can hardly expect an English grammar rule to apply.

  • nerf (unregistered)

    At least it uses stringbuilder, and doesn't use &=. Too bad he didn't go two down in intellisense...

    formattedPhoneNumber.AppendFormat("({0}) {1}-{2}", cleanPhoneNumber.Substring(0, 3), cleanPhoneNumber.Substring(4, 3), cleanPhoneNumber.Substring(7, 4))

  • (cs)

    Reminds me of Duff's device.

  • (cs) in reply to pscs
    pscs:
    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).

    Oh yea, English is such a clusterfuck of exceptions that it really is 'exceptional'. I have friends in Taiwan and Japan that I occasionally help with their English studies. Really makes you realize what a mess it all is when you try to explain it to someone and go "WTF..." in your mind. :)

  • Someone who likes shorter versions (unregistered)
    Public Shared Function ApplyPhoneNumberFormatting(ByVal phoneNumber As String) As String
        Dim cleanPhoneNumber As String
        
        If phoneNumber Is Nothing Then
            Return String.Empty
        End If
    
        cleanPhoneNumber = StripNonNumericCharacters(phoneNumber)
    
        If cleanPhoneNumber.Length = 0 Then
            Return String.Empty
        Else
            Return "(" + Mid(cleanPhoneNumber, 0, 3) + ")" + Mid(cleanPhoneNumber, 3, 3) + "-" + Mid(cleanPhoneNumber), 6, 4);
        End If
    End Function
    
  • Anonymous (unregistered)

    Please supply me with a firearm and the coder responsible for this abomination. Then just close the door behind you and pretend you didn't see me today.

  • Ditto (unregistered)

    Shouldn't that address be:

    For Loop Liberation Front 44 Front St. 2nd Floor Berea, OH 44017 USA End Loop

    ?? :\

    (Uh, and the CAPTCHA was: transverbero .. what the heck is that? a verb with questionable gender?) :o

  • len(10)=12 (unregistered) in reply to campkev
    campkev:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
    Using the same verification standard, I have verified that my ****** is 10 inches long.

    It may only be 10 inches, but sure smells like 1'

  • (cs) in reply to ContraCorners
    ContraCorners:
    Pim:
    I want to see what the StripNonNumericCharacters function looks like!
    My guess would be something like this... *snip*
    Even if you used a macro to generate that, you have waay too much time on your hands.
  • (cs)

    This FOR-CASE construct has been seen before on Daily WTF before I think. Really the only reason I can think of is to simulate line-numbers and most programs don't need them (even if they have them).

  • diaphanein (unregistered)

    Bah, this is nothing. I perhaps some of the most horrendous legacy code I inheritted, I have a single function that I've so far reduced to 977 lines (was previously +1500).

    At last count, there's over a dozen of non-const static locals (hooray for non-reentrant code).

    There are: 7 while loops. 25 for loops. 27 nested switch statements. 81 cases for those switch statements. 261 if statements. 123 else statements.

    As I said, this phone number loops is NOTHING. It's not a WTF, it's a meh.

  • More (unregistered) in reply to ContraCorners
    ContraCorners:
    Pim:
    I want to see what the StripNonNumericCharacters function looks like!
    My guess would be something like this... <snip>

    Don't be silly. This is much more eloquent:

    Public Function StripNonNumericCharacters(ByVal sOrginalPhoneNumber As String) As String
            Dim i As Integer
    
            Dim sCleanPhoneNumber
            If sOrginalPhoneNumber Is Nothing Then
                Return String.Empty
            Else
                For i = 0 To 83
                    Select Case i
                        Case 0
                            sCleanPhoneNumber = Replace(sOrginalPhoneNumber, "A", "")
                        Case 1
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "B", "")
                        Case 2
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "C", "")
                        Case 3
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "D", "")
                        Case 4
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "E", "")
                        Case 5
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "F", "")
                        Case 6
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "G", "")
                        Case 7
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "H", "")
                        Case 8
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "I", "")
                        Case 9
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "J", "")
                        Case 10
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "K", "")
                        Case 11
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "L", "")
                        Case 12
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "M", "")
                        Case 13
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "N", "")
                        Case 14
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "O", "")
                        Case 15
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "P", "")
                        Case 16
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "Q", "")
                        Case 17
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "R", "")
                        Case 18
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "S", "")
                        Case 19
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "T", "")
                        Case 20
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "U", "")
                        Case 21
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "V", "")
                        Case 22
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "W", "")
                        Case 23
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "X", "")
                        Case 24
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "Y", "")
                        Case 25
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "Z", "")
                        Case 26
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "a", "")
                        Case 27
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "b", "")
                        Case 28
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "c", "")
                        Case 29
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "d", "")
                        Case 30
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "e", "")
                        Case 31
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "f", "")
                        Case 32
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "g", "")
                        Case 33
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "h", "")
                        Case 34
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "i", "")
                        Case 35
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "j", "")
                        Case 36
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "k", "")
                        Case 37
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "l", "")
                        Case 38
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "m", "")
                        Case 39
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "n", "")
                        Case 40
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "o", "")
                        Case 41
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "p", "")
                        Case 42
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "q", "")
                        Case 43
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "r", "")
                        Case 44
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "s", "")
                        Case 45
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "t", "")
                        Case 46
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "u", "")
                        Case 47
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "v", "")
                        Case 48
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "w", "")
                        Case 49
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "x", "")
                        Case 50
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "y", "")
                        Case 51
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "z", "")
                        Case 52
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "`", "")
                        Case 53
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "~", "")
                        Case 54
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "!", "")
                        Case 55
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "@", "")
                        Case 56
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "#", "")
                        Case 57
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "$", "")
                        Case 58
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "%", "")
                        Case 59
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "^", "")
                        Case 60
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "&", "")
                        Case 61
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "*", "")
                        Case 62
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "(", "")
                        Case 63
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, ")", "")
                        Case 64
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "_", "")
                        Case 65
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "-", "")
                        Case 66
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "+", "")
                        Case 67
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "=[", "")
                        Case 68
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "]", "")
                        Case 69
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "\", "")
                        Case 70
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "{", "")
                        Case 71
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "}", "")
                        Case 72
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "|", "")
                        Case 73
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, ";", "")
                        Case 74
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "", "")
                        Case 75
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, ";", "")
                        Case 76
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, """", "")
                        Case 77
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "'", "")
                        Case 78
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "", "")
                        Case 79
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, ",.", "")
                        Case 80
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "/", "")
                        Case 81
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "<", "")
                        Case 82
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, ">", "")
                        Case 83
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "?", "")
    
                    End Select
                Next
                Return sCleanPhoneNumber
            End If
        End Function
    
  • Henk (unregistered)

    def bla(a): return '('+a[:3]+') '+a[3:6]+'-'+a[6:]

  • foo (unregistered) in reply to diaphanein
    diaphanein:
    Bah, this is nothing. I perhaps some of the most horrendous legacy code I inheritted, I have a single function that I've so far reduced to 977 lines (was previously +1500).

    At last count, there's over a dozen of non-const static locals (hooray for non-reentrant code).

    There are: 7 while loops. 25 for loops. 27 nested switch statements. 81 cases for those switch statements. 261 if statements. 123 else statements.

    As I said, this phone number loops is NOTHING. It's not a WTF, it's a meh.

    Awesome. I am applying for the domain name "thedailymeh.com". In the future please direct all of your submissions to me.

  • (cs) in reply to Kermos
    Kermos:
    pscs:
    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).

    Oh yea, English is such a clusterfuck of exceptions that it really is 'exceptional'. I have friends in Taiwan and Japan that I occasionally help with their English studies. Really makes you realize what a mess it all is when you try to explain it to someone and go "WTF..." in your mind. :)

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.

  • Buddy (unregistered) in reply to campkev
    campkev:
    Buddy:
    Horrendous.

    What is neat is that you can strip away, Picasso-style, and get at the essence of ApplyPhoneNumberFormatting.

    ...

    Ironic that in a post about removing unnecessary lines, you have an if-return-else statement.

    It's a work in progress, each step I have to tread every more carefully to ensure I capture the true essence of what is ApplyPhoneNumberFormatting.

    [image]
  • Dennis (unregistered) in reply to dpm
    dpm:
    campkev:
    some schmoe:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
    Where does it do that? I only see a check for length = 0, otherwise it assumes all the characters are there. So if cleanPhoneNumber comes back with only 9 chars or less, it will blow up.

    Let me help you out

    dpm:
    Yeah, the code sucks, <sarcasm>but at least the length is verified before they try to access all ten digits they expect to be there.</sarcasm>
    I beg your pardon! My claim that "the code sucks" was not sarcastic at all.

    fix'd

  • (cs) in reply to More
    More:
    ContraCorners:
    Pim:
    I want to see what the StripNonNumericCharacters function looks like!
    My guess would be something like this... <snip>

    Don't be silly. This is much more eloquent:

    Public Function StripNonNumericCharacters(ByVal sOrginalPhoneNumber As String) As String
            Dim i As Integer
    
            Dim sCleanPhoneNumber
            If sOrginalPhoneNumber Is Nothing Then
                Return String.Empty
            Else
                For i = 0 To 83
                    Select Case i
                        Case 0
                            sCleanPhoneNumber = Replace(sOrginalPhoneNumber, "A", "")
                        Case 1
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "B", "")
    < snip >
                        Case 83
                            sCleanPhoneNumber = Replace(sCleanPhoneNumber, "?", "")
    
                    End Select
                Next
                Return sCleanPhoneNumber
            End If
        End Function
    
    cc

    D'oh! What was I thinking?! Thanks for your help, I stand corrected.

  • SCB (unregistered) in reply to Brompot
    Brompot:
    campkev:
    dpm:
    Yeah, the code sucks, but at least the length is verified before they try to access all ten digits they expect to be there.
    Using the same verification standard, I have verified that my ****** is 10 inches long.
    My ruler is 12 inches. A much more common format.

    Maybe, but his is metric.

  • tombom (unregistered)

    Petition to name this XTREME CODING STYLE "Duff's Enigma"

  • (cs) in reply to campkev
    campkev:
    As an example, he asked if anyone could give the past tense of "I can go"?
    I used to be able to go (but now I wear a catheter).
  • Buddy (unregistered) in reply to campkev
    campkev:
    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.

    If I'm understanding correctly...

    Today, I can go, but yesterday, I could have gone.

  • Inno (unregistered) in reply to campkev
    campkev:

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.

    English is not my native language, but how about:

    1. I could go
    2. I could have gone
  • Anon (unregistered) in reply to campkev
    campkev:
    Kermos:
    pscs:
    The most accurate version of the 'i before e' saying is "i before e except where it isn't". Anything else is either going to be unrememberable or wrong.

    There are so many exceptions to this "rule", I've never been convinced how useful it is (science, eiderdown, deity, seismic, Keith, caffeine, seeing, ancient, society etc etc etc).

    I could of gone?

    Oh yea, English is such a clusterfuck of exceptions that it really is 'exceptional'. I have friends in Taiwan and Japan that I occasionally help with their English studies. Really makes you realize what a mess it all is when you try to explain it to someone and go "WTF..." in your mind. :)

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.

  • Anon (unregistered) in reply to campkev

    [quote user="campkev"][quote user="Kermos"]

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.[/quote]

    Sorry, messed that up:

    I could of gone?

  • (cs) in reply to Anon

    [quote user="Anon"][quote user="campkev"][quote user="Kermos"]

    Reminds me of the welcome speech from the Commandant of the Defense Language Institute. He said that once we got into our courses, some of us might start complaining about how hard the languages are to learn and how weird they are, but really, none of them are as hard to learn or as screwed up as English. As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.[/quote]

    Sorry, messed that up:

    I could of gone?[/quote]

    Yep, you definitely messed that up...

  • Devilfish (unregistered)

    If this doesn't make you cry, you have no soul.

  • BrianA (unregistered)

    Even VB6 can do it better:

    Public Function ApplyPhoneNumberFormatting(ByVal phoneNumber As String) As String

    Dim cleanPhoneNumber As String
    
    cleanPhoneNumber = StripNonNumericCharacters(phoneNumber)
    
    If cleanPhoneNumber.Length = 0 Then
        ApplyPhoneNumberFormatting = ""
    Else
        ApplyPhoneNumberFormatting = Format(cleanPhoneNumber, "(@@@) @@@-@@@@")
    End If
    

    End Function

  • (cs) in reply to Code Dependent
    Code Dependent:
    campkev:
    As an example, he asked if anyone could give the past tense of "I can go"?
    I used to be able to go (but now I wear a catheter).
    I could go
    I could have gone
    I could of gone?

    Four responses, all different. Is the right answer even necessary to make my point?

  • Sofa King (unregistered)
    As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.
    You're telling us not one of 300 people could come up with "I could have gone?" That seems implausible.
  • (cs) in reply to bobbytables
    bobbytables:
    How did I know this was going to be VB?
    Darn you beat me to my comment.
  • The Wanderer (unregistered) in reply to Sofa King
    Sofa King:
    As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.
    You're telling us not one of 300 people could come up with "I could have gone?" That seems implausible.
    That was my first thought as well, but isn't that a conditional (thus, past tense of "I could go") rather than a strict past tense?

    Which would (now that I think of it) seem to lead to "I can have gone" as the correct answer, but since I went through three other possibilities leading to it, the original point of English being complicated in this respect does seem to have some validity.

  • (cs) in reply to Sofa King
    Sofa King:
    As an example, he asked if anyone could give the past tense of "I can go"? Not one of the 300 or so people in the room, including me, could do it.
    You're telling us not one of 300 people could come up with "I could have gone?" That seems implausible.

    No, someone came up with "I could have gone", it just isn't right.

  • (cs) in reply to Anon
    Anon:
    I could of gone?
    I could of gone, except I of to of something to eat first.
  • (cs) in reply to Code Dependent
    Code Dependent:
    Anon:
    I could of gone?
    I could of gone, except I of to of something to eat first.

    Don't be mean, he did say he wasn't a native speaker, and if you've only heard it said, "could've gone" sounds a lot like "could of".

Leave a comment on “Formatting a Phone Number - The Long Version”

Log In or post as a guest

Replying to comment #:

« Return to Article