How do I search for quotation marks within a string?

T

tomcarr1

If I want to search for a character within a sring, I normally use

x = myString.IndexOf("T")

However, what if I want to look for a quotation mark within the string?

I have tried

x = myString.IndexOf(""")
x = myString.IndexOf(")
x = myString.IndexOf(" " ")

and so on. Nothing works. How do I do this?
 
L

Luc E. Mistiaen

Besides Greg's solution, when you you search for a single character, you can
also use single quote; between single quotes, you can use the double quote
character.

So x = myString.IndexOf('"') will work too (that is ', followed by " then ')

/LM
 
?

=?ISO-8859-1?Q?G=F6ran_Andersson?=

If you are using VB (which is my guess, as you have no semicolon at the
end of the statement):

x = myString.IndexOf("""")

If you are using C#:

x = myString.IndexOf("\"")
or
x = myString.IndexOf(@"""")
or
x = myString.IndexOf('"')
 
G

Guest

I don't consider a quotation mark as a control character, but, yes, that
is a good alternative. :)

A curious thing about the ControlChars class, though, is that it has a
public constructor. Does anybody know why? An instance of the class is
totally useless, as all members that are not inherited from Object are
constants.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top