Braun Schweitzer was tasked with reverse engineering a giant, VB6-based system at his company. No one knew everything that it did, nor did anyone really understood how it did it either. No less, they were determined to rewrite it and document it. Sadly, these circumstances on their own do not justify a "WTF" post.

However, I do think that this small snippet of code from the system has merit. Note that it is actually twice-removed from the proper solution of parameterized queries and somehow manages to avoid the obvious Replace ... twice in a row. But it's name and comment is what officially brings it into Whiskey Tango Foxtrot country ...

Private Function StripWeird(InTxt As String) As String
  Dim pos As Integer
      
  InTxt = Trim(Left(InTxt, 16000))
  
  'sql server freaks out on this character: '
  pos = InStr(1, InTxt, "'")
  Do While pos > 0
    InTxt = Left(InTxt, pos - 1) & Mid(InTxt, pos + 1)
    If pos > 1 Then
      pos = InStr(pos - 1, InTxt, "'")
    Else
      pos = InStr(1, InTxt, "'")
    End If
  Loop
  
  pos = InStr(1, InTxt, "'")
  Do While pos > 0
    InTxt = Left(InTxt, pos - 1) & Mid(InTxt, pos + 1)
    If pos > 1 Then
      pos = InStr(pos - 1, InTxt, "'")
    Else
      pos = InStr(1, InTxt, "'")
    End If
  Loop

  StripWeird = InTxt
End Function

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