Re: replace a string by McKirahan
McKirahan
Mon Sep 13 10:33:05 CDT 2004
"WebRaster" <web-master-@-wstaff.it> wrote in message
news:ci4bcf$5q4$1@newsread.albacom.net...
> Excuse my question wasn't clear
> I use a a variables passed by URL, a querystring e.g. "National Museum", I
> wish replace in the page all the occurences of "National Museum",
"National
> museum", "national Museum", and so on with "<b>National Museum</b>"
> I don't want to convert all text in lower case.
> Perhaps more clear
> Thank You
>
> McKirahan <News@McKirahan.com> wrote in message
> vbf1d.168694$9d6.88942@attbi_s54...
> > "WebRaster" <web-master-@-wstaff.it> wrote in message
> > news:ci3j59$gdp$1@newsread.albacom.net...
> > > Hy
> > > I need to replace a string in a large text BUT even occurrences are
> upper
> > or
> > > lower case
> > > e.g. Museo Archeologico, Museo archeologico, museo archeologico with
> > "Museo
> > > Archeologico"
> > >
> > >
> > > I can I do?
> > >
> > > Thanks
> >
> > Use LCase() to convert the string to lower case before using InStr() or
> > Replace().
> >
Try the following; watch for word-wrap.
Option Explicit
'*
Const cVBS = "museum.vbs"
'*
Dim intPOS
intPOS = 1
Dim arrTXT(2)
arrTXT(0) = "National Museum"
arrTXT(1) = "The 'national Museum' is the same as 'National
museum'."
arrTXT(2) = arrTXT(1)
Dim intTXT
Dim strTXT
'*
Do
intTXT = InStr(intPOS,LCase(arrTXT(1)),LCase(arrTXT(0)))
If intTXT = 0 Then Exit Do
strTXT = Mid(arrTXT(2),intTXT,Len(arrTXT(0)))
arrTXT(2) = Replace(arrTXT(2),strTXT,arrTXT(0))
intPOS = intTXT + Len(arrTXT(0))
Loop
'*
MsgBox arrTXT(0) & vbCrLf & arrTXT(1) & vbCrLf &
arrTXT(2),vbInformation,cVBS
This doesn't (yet) handle adding tags (i.e. <b></b>) but it does fix the
capitalizations.