Searching a Very Long String - Efficiently (Classic ASP)
When it comes to string handling, ASP isn't the most efficient. The easiest code to write is simply instr(1,ucase(search),ucase(find)), and then check the result for > 0. The problem comes with extremely long strings. I needed to search a very long string of values from each line of CSV. It was actually much faster to split each line into its individual elements and search one cell at a time. Here is the code.
Function CheckSearchString(sToCheck,sList) Dim aItems Dim bFound Dim i bFound = False aItems = Split(sList, ",") For i = lBound(aItems) to uBound(aItems) If instr(1,ucase(sToCheck),uCase(aItems(i))) > 0 Then bFound = true Exit For Else ' Response.Write sToCheck End If Next CheckSearchString = bFound End Function