Dear Daily WTF Readers,

Please, take a moment of your time to consider the plight of the poor 'for' loop and its sister 'case' in the below code which has chosen to remain anonymous as per its submitter.

Torn from their mother at an early age, they toil, day and night without rest, as a cog in some oversized corporate wheel.  They are forced, often brutally, to piecemeal together a hopefully valid telephone number from the leftovers of a processed string.  They're tired, hungry, and begging for retirement to that place in the sky where all bloated code goes when it dies.

So, please, send whatever you can (really, anything will do) to the For Loop Liberation Front world headquarters.

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

If you include a SASE, you'll recieve a Daily WTF sticker or two as a "thank you" for supporting this cause. 

Thank you. 

Public Shared Function ApplyPhoneNumberFormatting(ByVal phoneNumber As String) As String
        Dim cleanPhoneNumber As String
        Dim formattedPhoneNumber As New System.Text.StringBuilder
        Dim i As Integer

                If phoneNumber Is Nothing Then
                        Return String.Empty
                End If

        cleanPhoneNumber = StripNonNumericCharacters(phoneNumber)

        If cleanPhoneNumber.Length = 0 Then
            Return String.Empty
        Else

            For i = 0 To 12

                Select Case i
                    Case 0
                        formattedPhoneNumber.Append("(")
                    Case 1
                        formattedPhoneNumber.Append(cleanPhoneNumber.Chars(0))
                    Case 2
                        formattedPhoneNumber.Append(cleanPhoneNumber.Chars(1))
                    Case 3
                        formattedPhoneNumber.Append(cleanPhoneNumber.Chars(2))
                    Case 4
                        formattedPhoneNumber.Append(") ")
                    Case 5
                        formattedPhoneNumber.Append(cleanPhoneNumber.Chars(3))
                    Case 6
                        formattedPhoneNumber.Append(cleanPhoneNumber.Chars(4))
                    Case 7
                        formattedPhoneNumber.Append(cleanPhoneNumber.Chars(5))
                    Case 8
                        formattedPhoneNumber.Append("-")
                    Case 9
                        formattedPhoneNumber.Append(cleanPhoneNumber.Chars(6))
                    Case 10
                        formattedPhoneNumber.Append(cleanPhoneNumber.Chars(7))
                    Case 11
                        formattedPhoneNumber.Append(cleanPhoneNumber.Chars(8))
                    Case 12
                        formattedPhoneNumber.Append(cleanPhoneNumber.Chars(9))

                End Select

            Next

            Return formattedPhoneNumber.ToString

        End If

    End Function
[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!