How do I search for quotation marks within a string?

  • Thread starter Thread starter tomcarr1
  • Start date Start date
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?
 
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
 
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('"')
 
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.
 
Back
Top