VB Coding Tip: Trim a Selected Character From a String

Monday Nov 18th 2002 by Sam Huggill

Use Visual Basic to trim a selected character from a string.

Public Function TrimChar( _
         text As String, _
         char As String)

Dim trimspace As Integer
Dim thechar$, thechars$

If InStr(text, char) = 0 Then
  TrimChar = text
  Exit Function
End If

For trimspace = 1 To Len(text)

thechar$ = Mid(text, trimspace, 1)
thechars$ = thechars$ & thechar$

If thechar$ = char Then
  thechars$ = Mid( thechars$, 1, _
                   Len(thechars$) - 1)
End If

Next trimspace

TrimChar = thechars$

End Function
Private Sub cmdTrim_Click()
End Sub
Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved