When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Tuesday, September 29, 1998

VBScript Search and Kill Code

This code was written by Toby Gramm, webmaster of Techfools.com.

Search And Kill!

- continued -

Function SearchAndKill(s, s1, s2)
's The string to parse
's1 Starting Character or String
's2 Ending Character or String
' MyCleanString = SearchAndKill("#crap$ Hi I'm a Tech Fool #more crap$","#","$")
'Returns this:
' " Hi I'm a Tech Fool "
    Dim I
    Dim iPos
    Dim iPosEnd
    Dim sProduct
    Dim iLength

    iPos = InStr(s, s1)
    If iPos > 0 Then
        iPosEnd = InStr(iPos, s, s2)
        Exit Function
    End If
    If Not iPosEnd > 0 Then Exit Function
    iPosEnd = 1
    Do While True
        iPos = InStr(s, s1) + Len(s1)
        If Not iPos > Len(s1) Then Exit Do
        iPosEnd = InStr(iPos, s, s2) + len(s2) -1
        iLength = iPosEnd - iPos
        If Not iPosEnd > 0 Then iLength = Len(s)
        If s1 = "" Then
            iPos = 0
            iPos = iPos - (Len(s1) + 1)
        End If
        If s2 = "" Then
            iPosEnd = Len(s)
            iPosEnd = Len(s) - iPosEnd
        End If
        sProduct = Left(s, iPos) & Right(s, iPosEnd)
        s = sProduct
        If InStr(s, s1) = 0 And InStr(s, s2) = 0 Then Exit Do
    SearchAndKill = sProduct
End Function

Email: Toby Gramm

ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article