Solved

search for character " in instr function

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

706 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

15 Experts available now in Live!

Get 1:1 Help Now