Click to See Complete Forum and Search --> : Replace Text ignore case


jytioh
06-15-2004, 04:21 AM
I want to write a function that will replace text regardless of case. But I only know how to write the function as below, which is stupid and tedious. Anyone can guide me how to write one which will ignore the case? Is it possible to use regular expression?

Thanks.

<%
Function Rep_Chars(ReplaceText)

ReplaceText = Replace(ReplaceText, "****", "s***" )
ReplaceText = Replace(ReplaceText, "****", "S***" )
ReplaceText = Replace(ReplaceText, "****", "S***" )
ReplaceText = Replace(ReplaceText, "****", "S***" )
ReplaceText = Replace(ReplaceText, "****", "S***" )
ReplaceText = Replace(ReplaceText, "****", "S***" )
ReplaceText = Replace(ReplaceText, "****", "S***" )

Rep_Chars = ReplaceText

End Function
%>
<% StrText = "****, ****, ****, ****" %>
<%=Rep_Chars(StrText)%>

buntine
06-15-2004, 04:45 AM
I dont understand what your trying to achieve here. This function executes the same command seven times, each one overwriting the last.

To ignore case, you can use the UCase() or LCase() VBScript functions, which return a copy of the given parameter in either upper-case or lower-case, respectively.

Function rep_chars(strReplace)
rep_chars = Replace(UCase(strReplace), "****", "S***")
End Function

Regards,
Andrew Buntine.

jytioh
06-15-2004, 10:32 AM
Your solution don't seem to solve the problem. I want to preserve the case of the words.

For example... If I come across the word Microsoft and microsoft, I would like to bold them and preserve their case. ie Microsoft remains Microsoft after text replace and microsoft remains microsoft. And I want an array of words which I could replace.

buntine
06-15-2004, 10:48 AM
Ok, im a little shady on the whole idea here.

You want to create an array of words, which you would like to search for in a big string of text. If found, these words must be bolded and reserve their case.

Is that what you want to do?

jytioh
06-15-2004, 07:19 PM
yup. either bold or change colour. the text will be replaced regardless of case and after the change the case will still remain.

buntine
06-15-2004, 07:56 PM
Ok, i will have a go at it this afternoon.