Will this fit your requirement pare?
Code:Option Explicit Private Function Clean_String(strText As String) As String Dim str() As String Dim cntback As Long str = Split(strText, vbCrLf) For cntback = UBound(str) To 0 Step -1 If str(cntback) = vbTab Or str(cntback) = vbNewLine Or Len(str(cntback)) = 0 Or str(cntback) = vbCr Or str(cntback) = vbLf Then 'reduce size of array to remove last invalid entry ReDim Preserve str(UBound(str) - 1) Else Exit For End If Next Clean_String = Join(str, vbCrLf) End Function Private Sub Command1_Click() Dim s As String 'Valid TEXT line '< valid vbtab or vbnewline 'Valid TEXT line 'Valid TEXT line 'Valid TEXT line '< vbnewline (to be remove) '< vbtab (to be remove) '< vbtab vbtab (to be remove) '< vbnewline (to be remove) '< empty (to be remove) '< else that is blank (to be remove) s = "X" & vbNewLine s = s & vbTab & vbNewLine s = s & "Y" & vbNewLine s = s & "Z" & vbNewLine s = s & vbTab & vbNewLine s = s & vbNewLine & vbNewLine s = s & vbCr & vbNewLine s = s & vbLf & vbNewLine s = s & vbNullString & vbNewLine MsgBox Clean_String(s) End Sub




Reply With Quote