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

Sections:
Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
XML Info
Information:
Feedback
Author an Article
Technology Jobs
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
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
'Example:
' 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)
    Else
        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
        Else
            iPos = iPos - (Len(s1) + 1)
        End If
        If s2 = "" Then
            iPosEnd = Len(s)
        Else
            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
        
    Loop
    SearchAndKill = sProduct
End Function


Email: Toby Gramm



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