If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Insensitive case string replace

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-05-04, 05:36
dove_g dove_g is offline
Registered User
 
Join Date: Jan 2004
Posts: 30
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.
Reply With Quote
  #2 (permalink)  
Old 03-06-04, 23:14
gyuan gyuan is offline
Registered User
 
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.
Reply With Quote
  #3 (permalink)  
Old 03-07-04, 20:42
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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
Reply With Quote
  #4 (permalink)  
Old 03-09-04, 02:51
dove_g dove_g is offline
Registered User
 
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)
%>
Reply With Quote
  #5 (permalink)  
Old 03-09-04, 17:04
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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...
Reply With Quote
  #6 (permalink)  
Old 03-10-04, 02:18
dove_g dove_g is offline
Registered User
 
Join Date: Jan 2004
Posts: 30
I didn't know how to use function , I will check it on web.
Reply With Quote
  #7 (permalink)  
Old 03-10-04, 15:50
rokslide rokslide is offline
Registered User
 
Join Date: Nov 2003
Location: Christchurch, New Zealand
Posts: 1,617
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On