By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,971 Members | 1,451 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,971 IT Pros & Developers. It's quick & easy.

How do I search for quotation marks within a string?

P: n/a
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?

Jul 7 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
try "\""

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

<to******@gmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
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?

Jul 7 '06 #2

P: n/a
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

<to******@gmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
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?

Jul 8 '06 #3

P: n/a
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('"')

to******@gmail.com wrote:
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?
Jul 8 '06 #4

P: n/a
guy
use ControlChars.Quote, it is more readable (or at least i think so;-)

hth guy

"to******@gmail.com" wrote:
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?

Jul 9 '06 #5

P: n/a
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.

guy wrote:
use ControlChars.Quote, it is more readable (or at least i think so;-)

hth guy

"to******@gmail.com" wrote:
>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?

Jul 9 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.