Tools Links Login

Strip Characters from a string

This function is to strip all instances of a character out of a string. Its fairly compact and simple. Hope its helpful to someone. :)

Original Author: async tea

Returns

The original string without the character in str2Strip

Code

Function stripChar(str2BStriped As String, str2Strip As String) As String
  Dim sPos As Long
  Dim newStr As String
  
  sPos = 1
  Do
    sPos = InStr(str2BStriped, str2Strip)
    If sPos > 0 Then
      newStr = newStr & Left(str2BStriped, sPos - 1)
    Else
      newStr = newStr & str2BStriped
    End If
    str2BStriped = Right(str2BStriped, Len(str2BStriped) - sPos)
  Loop Until sPos = 0
  stripChar = newStr
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 111 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

AnonymousCoward posted this comment on 2021-06-28:

BOOM

dwirch posted this comment on 2021-06-28:

It should be noted that in Visual Basic 6 (VB6), the same can be accomplished with a single line of code, as shown below.

strMyString = "This is a test of the emergency broadcast system."
strMyString = Replace(strMyString, "e", "")

In this example, the first line sets the string value, while the second line removes all instances of the letter e from the string.

For more information on replace and other string functions, see this link.

You must be logged in to make a comment.