469,327 Members | 1,128 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

Replace Double-Quote

Hi there,

If I have a string var, strFoo that contains double-quotes such that it
looks like this: I "love" VB

What do I pass into the "replace" method to replace the double-quotes with
something else?

strFoo = strFoo.replace(???,""")

In other words, what would I pass in inplace of the ??? above to get rid of
any double quotes in the string var strFoo?

Thanks,

Kevin
Nov 21 '05 #1
4 23685
You have to escape the " character, that's all.

The way to do that is replace instances of " with "".

Sample code -

Try
Dim str As String = "I ""love"" VB"
Console.WriteLine(str)
Console.WriteLine(str.Replace("""", ""))
Catch ex As Exception
Console.Write(ex.ToString())
Finally
Console.Read()
End Try
- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
"Kevin Thomas" <Ke***@FakeEmailAddresses.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi there,

If I have a string var, strFoo that contains double-quotes such that it
looks like this: I "love" VB

What do I pass into the "replace" method to replace the double-quotes with
something else?

strFoo = strFoo.replace(???,"&quot;")

In other words, what would I pass in inplace of the ??? above to get rid of any double quotes in the string var strFoo?

Thanks,

Kevin

Nov 21 '05 #2
"Kevin Thomas" <Ke***@FakeEmailAddresses.com> schrieb:
If I have a string var, strFoo that contains double-quotes such that it
looks like this: I "love" VB

What do I pass into the "replace" method to replace the double-quotes with
something else?

strFoo = strFoo.replace(???,"&quot;")


'... = strFoo.Replace("""", "&quot;")'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #3
Thanks everyone for your quick response.

The funny thing here is that I was escaping the " with """" but when viewing
my output in IE, the browser was itself changing the &quot; back into " for
easy viewing, thus convincing me that it was imposible to replace a
double-quote. Once I viewed source in IE, I saw that the double-quote was
getting replaced.

Thanks again!

Kevin
"Sahil Malik" <co*****************@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
You have to escape the " character, that's all.

The way to do that is replace instances of " with "".

Sample code -

Try
Dim str As String = "I ""love"" VB"
Console.WriteLine(str)
Console.WriteLine(str.Replace("""", ""))
Catch ex As Exception
Console.Write(ex.ToString())
Finally
Console.Read()
End Try
- Sahil Malik
You can reach me thru my blog at
http://www.dotnetjunkies.com/weblog/sahilmalik
"Kevin Thomas" <Ke***@FakeEmailAddresses.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
Hi there,

If I have a string var, strFoo that contains double-quotes such that it
looks like this: I "love" VB

What do I pass into the "replace" method to replace the double-quotes
with
something else?

strFoo = strFoo.replace(???,"&quot;")

In other words, what would I pass in inplace of the ??? above to get rid

of
any double quotes in the string var strFoo?

Thanks,

Kevin


Nov 21 '05 #4
Kevin,
In addition to the other comments, you can use also ControlChars.Quote.
strFoo = strFoo.replace(ControlChars.Quote,"&quot;")
However it appears that you are doing something with HTML or XML, rather
then attempting to use String.Replace to create well formed HTML or XML I
would use one of the Framework classes that already do this.

Such as:

HttpUtility.HtmlEncode & HttpUtility.HtmlDecode
HttpServerUtility.HtmlEncode & HttpServerUtility.HtmlDecode

XmlTextWriter & XmlTextReader

Depending on what you are really trying to do there may be other more
appropriate classes.

Hope this helps
Jay
"Kevin Thomas" <Ke***@FakeEmailAddresses.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl... Hi there,

If I have a string var, strFoo that contains double-quotes such that it
looks like this: I "love" VB

What do I pass into the "replace" method to replace the double-quotes with
something else?

strFoo = strFoo.replace(???,"&quot;")

In other words, what would I pass in inplace of the ??? above to get rid
of any double quotes in the string var strFoo?

Thanks,

Kevin

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by middletree | last post: by
3 posts views Thread by Roy Adams | last post: by
6 posts views Thread by Shawn | last post: by
2 posts views Thread by P1ayboy | last post: by
3 posts views Thread by Christopher Benson-Manica | last post: by
4 posts views Thread by Derek Martin | last post: by
11 posts views Thread by jarod1701 | last post: by
2 posts views Thread by Neeta | last post: by
6 posts views Thread by =?Utf-8?B?R2Vvcmdl?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by listenups61195 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.