Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2004
    Posts
    30

    Unanswered: Insensitive case string replace

    I have one function on my web where I use one string to search some datafields. After finding and listing this articles, I would like to termin by which user has searched to be marked.

    Something like that:

    Replace(MyString,Termin,""<b>""&Termin&""</b>"")

    This works great but only if characters case matched, so how to make replace insensitive to upper and lower characters.

  2. #2
    Join Date
    Dec 2003
    Posts
    454
    You can use one of the following functions.

    LCase(string) returns a string that has been converted to lowercase.

    UCase(string) returns a string that has been converted to uppercase.

  3. #3
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    what you need to do is use the lcase and ucase functions as gyuan meantioned but you need to use them to locate the string and not replace it... once you have located the string then you can wrap it in bold tags,... some thing like.....
    Code:
    function highlight(yourString, strToHighlight)
      tmpString = LCase(yourString)
      startLoc = instr(1, lcase(yourString), strToHighlight)
      endLoc - startLoc + len(strToHighlight)
      resultString = left(yourString, startLoc)
      resultString = resultString & "<b>" & strToHighlight & "</b>"
      resultString = resultString & mid(yourString, endLoc)
      highlight = resultString
    end function
    You should of course make this a lot prettier and robust and make sure that the start and end locations are right (they might be out by one) but in priniciple it is what you need to do

  4. #4
    Join Date
    Jan 2004
    Posts
    30
    Thanks a lot, my code looks like that:

    <%
    myString = rsArtikli.Fields.Item("Naziv").Value
    startLoc = instr(1, lcase(myString), Pojam)
    resultString = left(myString, startLoc-1) & "<font color=""red"">"
    resultString = resultString & mid(myString,startLoc,len(pojam)) & "</font>"
    resultString = resultString & mid(myString,startLoc+len(pojam))
    Response.Write(resultString)
    %>

  5. #5
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    If the phrase appears only once that will work great,.. what is it appears twice, do you want both instances highlighted??

    Setting it up in a function would be a lot useful later I think...

  6. #6
    Join Date
    Jan 2004
    Posts
    30
    I didn't know how to use function , I will check it on web.

  7. #7
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    see how my code is written as a function above??

    You can call it by simply going...

    response.write highlight(myField)

    Just have the function at the end of all your asp code.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •