• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 792
  • Last Modified:

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
0
daniellyh
Asked:
daniellyh
  • 2
1 Solution
 
GrahamSkanCommented:
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
 
GrahamSkanCommented:
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

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now