October 24, 2018
Hot Topics:

VB Coding Tip: Trim a Selected Character From a String

  • November 19, 2002
  • By Sam Huggill
  • Send Email »
  • More Articles »
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

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date