Remove Spaces (or other characters) from a String
#5
I just did one of these the other day, and it's in my BadLimits post:

Code: (Select All)
Function RemoveCharacters$ (passed_from_what As String, what_character As String, from_which_side As Integer)
    'from_which_side: 1 = left, 2 = right, 3 = left and right, 0 = whole string
    Dim from_what As String
    from_what = passed_from_what
    If from_which_side = 0 Then 'strip from the whole string
        Do
            p = InStr(from_what, what_character)
            If p Then from_what = Left$(from_what, p - 1) + Mid$(from_what, p + 1)
        Loop Until p = 0
    End If
    If from_which_side And 1 Then 'strip from the left
        Do Until Left$(from_what, 1) <> what_character
            from_what = Mid$(from_what, 2)
        Loop
    End If
    If from_which_side And 2 Then 'strip from the right
        Do Until Right$(from_what, 1) <> what_character
            from_what = Left$(from_what, Len(from_what) - 1)
        Loop
    End If
    RemoveCharacters = from_what
End Function



Use the above function to remove from left side, right side, or the whole string, whatever characters you want removed.  Smile
Reply


Messages In This Thread
RE: Remove Spaces (or other characters) from a String - by SMcNeill - 12-29-2022, 04:09 AM



Users browsing this thread: 4 Guest(s)