Make a replace case insensitive in Classic ASP (VBScript)

2

I have the string below:

texto = "Meu texto"

I would like to make a replace in the word "My" and return it in bold. The result would look like this:

My text

However, replace is case sensitive, that is, if I use replace(texto,"meu","<b>meu</b>") nothing happens because of the capital 'M'.

Is there any way I can do a classic ASP replace with VBScript ignoring uppercase or lowercase letters? Or is it easier to do this in JavaScript or jQuery?

  

Note: I could convert everything to lowercase, but I want the return to keep the uppercase letters of the string.

    
asked by anonymous 31.07.2017 / 04:03

1 answer

1

The syntax of Replace of ASP VBScript is as follows:

  

Replace(string,find,replacewith[,start[,count[,compare]]])

where the last parameter compare should be placed 1 which is < in> search by text ( Explanation: 1 = vbTextCompare textual form string comparison (Insensitive) ) being the default 0 > which is binary search , so the change is not made.

Example:

<%

    Dim texto
    texto = "Meu texto"

    Response.Write ( replace(texto,"meu","<b>Meu</b>", 1, -1, 1) )
    Response.Write ( "<br />")
    Response.Write ( replace(texto,"mEu","<b>Meu</b>", 1, -1, 1) )
    Response.Write ( "<br />")
    Response.Write ( replace(texto,"meU","<b>Meu</b>", 1, -1, 1) )
    Response.Write ( "<br />")
    Response.Write ( replace(texto,"MEU","<b>Meu</b>", 1, -1, 1) )
    Response.Write ( "<br />")    

%>

Output:

  

My text

     

My text

     

My text

     

My text

31.07.2017 / 04:50