Solved

search for character " in instr function

Posted on 2004-09-07
3
762 Views
Last Modified: 2013-12-25
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
Comment
Question by:daniellyh
  • 2
3 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 50 total points
ID: 11995097
It's easiest  to use chr$(34)

MyPos = Instr(4, SearchString, Chr$(34), 1)  
0
 
LVL 8

Expert Comment

by:mladenovicz
ID: 11995113
   s = "string1""" & "string2"
    MsgBox s
    MsgBox InStr(s, """")
0
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 11995202
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now