How do I check for a string within a string irrespective of case? - TechRepublic
Question
July 29, 2011 at 11:45 PM
davidcon999

How do I check for a string within a string irrespective of case?

by davidcon999 . Updated 14 years, 11 months ago

I am extracting strings from HTML pages:
1 “Test <font size = ‘4’>text size</font> sample”
but I could have
2 “Test <FONT size = ‘4’>text size</font> sample”
or perhaps
3 “Test <font SIZE = ‘4’>text size</font> sample”
or even
4 “Test <FONT SIZE = ‘4’>text size</font> sample”

Ok so what I want to do is confirm that the string I have extracted contains the phrase “FONT SIZE”, irrespective of case.

So, having extracted the HTML into a string called HTMLText and thinking that CompareMethod.Text did just this, I coded:

Dim FontSizeTagStart as integer

FontSizeTagStart = HTMLText.IndexOf(“FONT SIZE”, CompareMethod.Text)

but unless I have string 4 above (which correctly gives a result for FontSizeTagStart of 6) I get a result for FontSizeTagStart of -1.

Clearly I’m doing something wrong but can anyone point out what it is please.

This discussion is locked

All Comments