Can someone tell me how to use the Replace() function in an ASP page and have it ignore case?
I.E. I'd want:
to return "Matt" wether the original value of sTemp was "Matthew, "MATTHEW" or "matthew".Code:sTemp=Replace(sTemp, "matthew", "Matt")
I though it'd be simple but in ASP the Replace function seems to be case sensitive...after leafing through the help file I found that I could gve it a value of vbTextCompare for the Compare argument, or if I stuck Option Compare Text at the top of the file that it should be case insensitive, but both approaches produce errors (usually "Type Mismatch").
For what it's worth the code I've got is:
You might see that I had a go at writing my own Replace function but it usually timed out and sometimes it didn't like the Left() function!!!!!Code:Function ElimiSwear(txt) sTemp = txt Set oRSElimiSwear = Server.CreateObject("ADODB.RecordSet") oRSElimiSwear.Open "SELECT word, replacement FROM ElimiSwear", oConn 'Response.Write "#" & vbTextCompare & "#" If Not oRSElimiSwear.BOF And Not oRSElimiSwear.EOF Then oRSElimiSwear.MoveFirst Do Until oRSElimiSwear.EOF sWord = oRSElimiSwear("word") sReplacement = oRSElimiSwear("replacement") If IsNull(sReplacement) Or IsEmpty(sReplacement) Or (sReplacement = "") Then sReplacement = MakeStars(sWord) sTemp = Replace(sTemp, sWord, sReplacement) ' Damn!! Replace function is case sensitive!! 'iPos = Instr(lcase(sTemp), lcase(sWord)) 'Response.Write "#" & iPos & "#" 'Do While iPos > 0 ' 'Response.Write "#" & iPos & "#" ' sTemp = Left(sTemp,iPos) & sReplacement & Right(sTemp, Len(sTemp) - iPos - Len(sWord)) ' iPos = Instr(lcase(sTemp), lcase(sWord)) 'Loop oRSElimiSwear.MoveNext Loop End If oRSElimiSwear.Close Set oRSElimiSwear = Nothing ElimiSwear = sTemp End Function Function MakeStars(txt) For iCounter = 1 To Len(txt) sTemp = sTemp & "*" Next MakeStars = sTemp End Function
I also tried: http://www.vb-world.net/tips/tip110.html
But again it moaned about the Left() function.
Am I missing something obvious? Help me!!!!!





Reply With Quote