E' stato un bel esercizio, ancora migliorabile però...
codice:
<%
varText = "Giorgio sta mangiando una mela che sa di 'cannella' acida, forse perché il cervello si era già bruciato di acidi molto tempo prima"
varSrc = "cannella"
iScarto = 3
arrCaratteri= array(".",",",";",":","!","?","'")
if instr(varText," ") > 0 then
varText = split(varText)
end if
if isArray(varText) then
for i = 0 to uBound(varText)
tempParola = varText(i)
elA = false
for y = 0 to uBound(arrCaratteri)
if right(tempParola,1) = arrCaratteri(y) then
elA = true
tempParola = left(tempParola,len(tempParola) - 1)
exit for
end if
next
elB = false
for z = 0 to uBound(arrCaratteri)
if left(tempParola,1) = arrCaratteri(z) then
elB = true
tempParola = mid(tempParola,2)
exit for
end if
next
if tempParola = varSrc then
outString = "" & tempParola & ""
if elA then outString = outString & arrCaratteri(y)
if elB then outString = arrCaratteri(z) & outString
exit for
end if
next
i = i - 1
if len(outString) > 0 then
if (i - iScarto) < 0 then
min = lBound(varText)
else
min = i - iScarto
end if
for x = i to min + 1 step - 1
outString = varText(x) & " " & outString
next
i = i + 2
if (i + iScarto) > uBound(varText) then
max = uBound(varText)
else
max = i + iScarto
end if
for x = i to max - 1
outString = outString & " " & varText(x)
next
end if
if len(outString) > 0 then
outString = "... " & outString & "..."
else
outString = "Nessuna corrispondenza"
end if
else
if varText = varSrc then
outString = "" & varText & ""
else
outString = "Nessuna corrispondenza"
end if
end if
response.write outString
%>