PDA

View Full Version : Search for a string with " char.



alpignolo
08-31-2013, 12:35 PM
Hello,

I have a problem in finding the position number of a string, using the function Instr().

I need to search for a string containing the " character, like:
<meta itemprop="price" content="

I would use something like:



stringAll = htm.body.innerHTML
X = "<meta itemprop=" & chr(34) & "price" & chr(34) & " content=" & chr(34)
position = Instr(1, stringAll , X, vbTextCompare)

but it returns 0.

What could be wrong with this piece of code?

Thank you

Alpignolo

ZVI
08-31-2013, 01:46 PM
Use x = "<meta itemprop=""price"" content="""

snb
08-31-2013, 03:32 PM
no need for variables:


position = Instr(htm.body.innerHTML , replace("<meta itemprop=~price~ content=~","~",chr(34)))

Since you didn't show the content of htm.body.innerHTML, the result 0 could be correct.

SamT
09-01-2013, 08:20 AM
HeadEnd = InStr(1, stringAll, "</Head", vbTextCompare)

Position = InStr(1, stringAll, "Price", vbTextCompare)

If Position > HeadEnd Then
Fail
Else
Position = Position - 15 'For "<", +26 for Price value
End If