search for character " in instr function

hi all,

i try to search for character " in a string variable using instr function in vb, but something gone wrong.

for e.g i define searchchar = """ but in vb it automatically appear as searchchar = """".my code is as below:

Dim SearchChar,mypos
SearchChar = """   ' Search for """ but it will automatically appear as searchchar = """".

MyPos = Instr(4, SearchString, SearchChar, 1)  

can suggest wat is the correct way to search for " in instr function?

thx in advance.

rgds,
daniel
LVL 1
daniellyhAsked:
Who is Participating?
 
GrahamSkanConnect With a Mentor RetiredCommented:
It's easiest  to use chr$(34)

MyPos = Instr(4, SearchString, Chr$(34), 1)  
0
 
mladenoviczCommented:
   s = "string1""" & "string2"
    MsgBox s
    MsgBox InStr(s, """")
0
 
GrahamSkanRetiredCommented:
If you want to use the " character,  the four in a row :  """" that the VB editor changes the three in a row into, will produce a string of one ", so will work as you wish in the Instr function.

You must double any single " in a string to get it treated as one. That's why you need the four.

But I find it hard to read which is why I recommend the Chr(34).
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.