Solved

search for character " in instr function

Posted on 2004-09-07
3
784 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

726 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