Heres what I came up with, (with some optimizing help from anhn).
This is mainly usefull for users of FireFox when copying posted source code in VBForums.
Code:
' Code Cleaner v1.2 - Ed Wilk / Edgemeal May 29th, 2008
'
' Removes prefixed spaces if all lines
' have at least one prefixed space character.
' Removes those unwanted lines with numbers and # characters.
Public Function CodeCleaner(sText As String) As String
Dim s() As String
Dim l As Long, EmptySpace As Long
Dim RemovedItem As Boolean
' put text into array, seperated by carraige returns.
s = Split(sText, vbCrLf)
' remove empty array items and items that start with a number or a "#" character.
Do
RemovedItem = False
For l = 0 To UBound(s)
If Len(s(l)) = 0 Or IsNumeric(s(l)) Or (s(l)) = "#" Then
RemoveArrayItem s, l
RemovedItem = True
Exit For
End If
Next l
If RemovedItem = False Then Exit Do
Loop
' remove excess prefix space characters.
Do
For l = 0 To UBound(s)
If Mid$(s(l), 1, 1) <> " " Then Exit Do
Next l
For l = 0 To UBound(s)
s(l) = Mid$(s(l), 2)
Next l
Loop ' check for more prefixed spaces.
' Re-Join array items & return.
CodeCleaner = Join(s, vbCrLf)
End Function
Private Sub RemoveArrayItem(ByRef Arry As Variant, ByVal Lindex As Long)
Dim k As Long
If Lindex < UBound(Arry) Then
For k = Lindex To UBound(Arry) - 1
Arry(k) = Arry(k + 1)
Next k
End If
ReDim Preserve Arry(UBound(Arry) - 1)
End Sub