Blog: Tag Archives: Strip Text

ASP – Strip Text between two known tags

Posted On:


'=== extractor function
'=== strSrc: the text to pull from
'=== strLft: left marker to start at
'=== strRgt: right marker to end at
function parser(strSrc, strLft, strRgt)
        dim strParsed
        strLft = cStr(strLft)
       
        if strLft = "1" then '=== start from beginning
                if inStr(strSrc, strRgt) > 0 then strParsed = left( strSrc, inStr(strSrc, strRgt) - 1)   
        elseif strLft = "" then '=== start from right marker (trim out last result)
                if inStr(strSrc, strRgt) > 0 then strParsed = right( strSrc, len(strSrc) - (inStr(strSrc, strRgt) + len(strRgt) - 1))
        else
                if inStr(strSrc, strLft) > 0 then
                        strParsed = right( strSrc, len(strSrc) - (inStr(strSrc, strLft) + len(strLft) - 1))
                        if inStr(strSrc, strRgt) > 0 then strParsed = left( strParsed, inStr(strParsed, strRgt) - 1)
                end if
        end if
       
        strParsed = trim(strParsed)
       
        do until left(strParsed, 1) <> chr(10) and right(strParsed, 1) <> chr(10)
                if left(strParsed, 1) = chr(10) then strParsed = right(strParsed, len(strParsed) - 1)
                if right(strParsed, 1) = chr(10) then strParsed = left(strParsed, len(strParsed) - 1)
        loop
       
        strParsed = replace( strParsed, "%20", " ")
        strParsed = trim(strParsed)
       
        parser = strParsed
end function

strQuery = "SELECT * FROM tblCactuShopOrderNumbers WHERE ON_Details LIKE '%Card Number: 0%'"
objRecordSet.Open strQuery, objDataConn, 1, 2, 1
DO WHILE NOT objRecordSet.EOF
strOrderDetails = objRecordSet("ON_Details")
text=parser(strOrderDetails, "<CardDetails>", "</CardDetails>")
strOrderDetails=Replace(strOrderDetails, text, "*** Card Details Deleted For Security Reasons ***")
objRecordSet("ON_Details")=strOrderDetails
objRecordSet.Update
objRecordSet.MoveNext
LOOP
objRecordSet.close