Results 1 to 4 of 4

Thread: Advanced Trim Function

  1. #1

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Advanced Trim Function

    This might not be the best way but it works :

    VB Code:
    1. Private Function ATrim(Str As String, Trim As String, MatchCase As Boolean) As String
    2.     Dim Check As Boolean
    3.     Check = True
    4.     Do While Check = True
    5.         If MatchCase = True Then
    6.             If Left$(Str, Len(Trim)) = Trim Then
    7.                 Str = Mid$(Str, Len(Trim) + 1)
    8.             Else
    9.                 Check = False
    10.             End If
    11.         Else
    12.             If LCase(Left$(Str, Len(Trim))) = LCase(Trim) Then
    13.                 Str = Mid$(Str, Len(Trim) + 1)
    14.             Else
    15.                 Check = False
    16.             End If
    17.         End If
    18.     Loop
    19.     Check = True
    20.     Do While Check = True
    21.         If MatchCase = True Then
    22.             If Right$(Str, Len(Trim)) = Trim Then
    23.                 Str = Mid$(Str, 1, Len(Str) - Len(Trim))
    24.             Else
    25.                 Check = False
    26.             End If
    27.         Else
    28.             If LCase(Right$(Str, Len(Trim))) = LCase(Trim) Then
    29.                 Str = Mid$(Str, 1, Len(Str) - Len(Trim))
    30.             Else
    31.                 Check = False
    32.             End If
    33.         End If
    34.     Loop
    35.     ATrim = Str
    36. End Function


    Has someone helped you? Then you can Rate their helpful post.

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Thanks. I'll used this in all my advanced applications.

  3. #3

    Thread Starter
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171


    Has someone helped you? Then you can Rate their helpful post.

  4. #4
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: Advanced Trim Function

    small bug:

    Debug.Print ATrim("bill smath", "a", True)


    Prints bill smath

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