CodeItBetter Programming Another VB Programming Blog

How to Strip/Remove Text from a given String

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'String Manipulation - How to Strip/Remove Text from a given String
Option Explicit
 
'This function removes a string from a string. Then returns the remaining
'string. Example: Strip("aaa-4f-dfddd","-") returns "aaa4fdfddd"

'This function is the same as using Replace with "" as the third parameter,
'but this provides one less parameter and also will work on versions below
'VB6 that don't support replace.

Public Function Strip(ByVal sExpression As String, ByVal sRemoveStr As String) As String
    Dim iLoc As Integer
    iLoc = InStr(sExpression, sRemoveStr)
    Do While iLoc > 0
        sExpression = Left(sExpression, iLoc - 1) & Mid(sExpression, iLoc + Len(sRemoveStr))
        iLoc = InStr(sExpression, sRemoveStr)
    Loop
    Strip = sExpression
End Function
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.