Results 1 to 7 of 7

Thread: [RESOLVED] Better Clean String

Threaded View

  1. #1

    Thread Starter
    Addicted Member xavierjohn22's Avatar
    Join Date
    Oct 2006
    Location
    Approx. 4921' and 3.11" asl
    Posts
    249

    Resolved [RESOLVED] Better Clean String

    Hi Stringers, I have this in my CS project, i search at the post here, the last part of my code from the forum search i did.
    What's better way to clean this kind of string only at the end.

    SAMPLE TEXT:
    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)

    What i am doing is expecting and removing any occurences of tab, newline or any empty line at the end. I counted backwards.

    'vbtab is len=1
    'newline = 0
    Code:
    Private Function Clean_String(strText As String) As String
        Dim str() As String
        Dim cntback As Long
        Dim cntforward
        Dim Counter As Long
        Dim strFinal As String
        str = Split(strText, vbCrLf)
        Counter = UBound(str)
        For cntback = UBound(str) To 0 Step -1
                'Debug.Print Len(str(cntback))
            If str(cntback) = vbTab Then
                'Debug.Print "tab" 
            ElseIf str(cntback) = vbCrLf Then
                'vbcrlf
            ElseIf Len(str(cntback)) > 0 Then
                'Debug.Print counter
                For cntforward = 0 To Counter
                    strFinal = strFinal & str(cntforward) & vbCrLf
                Next cntforward
                Exit For
            End If
            Counter = Counter - 1
        Next cntback
            
        If Right(strFinal, 2) = vbNewLine Then strFinal = Left(strFinal, Len(strFinal) - 2)
        If Right(strFinal, 1) = vbLf Then strFinal = Left(strFinal, Len(strFinal) - 1)
        If Right(strFinal, 1) = vbCr Then strFinal = Left(strFinal, Len(strFinal) - 1)
        Clean_String = strFinal
    End Function
    Last edited by xavierjohn22; Aug 11th, 2010 at 02:41 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width