문자열중 KeywordHighlighting 처리합니다.

실행을 하면 Highlight function 에 인자로 넘겨주는 '하이라이트' 의 색깔을 아래와 같이 바꿉니다.  Font Color도  인자로 넘길때

지정 가능합니다.

예) 하이라이트 예제입니다. replace function에 의해서 replace는 bold 처리하고 하이라이트 function에 의해서 '하이라이트'는 붉은 색으로 처리합니다.


만드신분 : Konstantin Vasserman (CodeProject)


<%


myText = "하이라이트 예제입니다. replace function에 의해서 replace는 bold 처리하고 "
myText = myText & "하이라이트 function에 의해서 '하이라이트'는 붉은 색으로 처리합니다."
myText = Replace(myText, "replace", "<b>replace</b>", 1, -1, 1)


'*****************************************************************************
' HIGHLIGHT function will search text for a specific string
' When string is found it will be surrounded by supplied strings
'
' NOTE: Unfortunately Replace() function does not preserve the original case
' of the found string. This function does.
'
' Parameters:
' strText  - string to search in
' strFind - string to look for
' strBefore - string to insert before the strFind
' strAfter  - string to insert after the strFind
'
' Example:
' This will make all the instances of the word "the" bold
'
' Response.Write Highlight(strSomeText, "the", "<b>", "</b>")
'
Function Highlight(strText, strFind, strBefore, strAfter)

 Dim nPos
 Dim nLen
 Dim nLenAll
 
 nLen = Len(strFind)
 nLenAll = nLen + Len(strBefore) + Len(strAfter) + 1

 Highlight = strText

 If nLen > 0 And Len(Highlight) > 0 Then
  nPos = InStr(1, Highlight, strFind, 1)
  Do While nPos > 0
   Highlight = Left(Highlight, nPos - 1) & _
    strBefore & Mid(Highlight, nPos, nLen) & strAfter & _
    Mid(Highlight, nPos + nLen)

   nPos = InStr(nPos + nLenAll, Highlight, strFind, 1)
  Loop
 End If
End Function
'********************************************************************************


Response.Write Highlight(myText, "하이라이트", "<font color=red>", "</font>")

%>

2008/02/21 15:54 2008/02/21 15:54

Trackback Address :: https://youngsam.net/trackback/176