473,231 Members | 1,826 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

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 24309
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: middletree | last post by:
What's wrong with this code? strLongDesc = Replace(Replace(Replace(Replace(Trim(Request.Form("LongDesc")),"'","''"),vbC rLf,"<br>"),"<",&lt;),"<",&gt;) Background: This field is a textarea, and I...
3
by: Roy Adams | last post by:
Hi group I'm having trouble using the replace command Here's my code below <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%> <!--#include file="../../Connections/conn.asp" --> <% if(...
6
by: Shawn | last post by:
Hi. I have a form with a couple of text fields where users can enter some data. The data is stored in an access DB. the problem is that whenever a user enters " in a textbox some of the text...
2
by: P1ayboy | last post by:
I have a string that contains double quotes. I need to replace these, but how can i do it as the code would be: replace(string,""","") Is there a way of breaking out of the double quotes? ...
3
by: Christopher Benson-Manica | last post by:
Why doesn't this replace all double quotes in a string with the letter Q? source.replace( /"(*)"/g, "Q$1Q" ); -- Christopher Benson-Manica | I *should* know what I'm talking about - if I...
6
by: G. | last post by:
This is an obvious bug in the String.Replace function: //load a XML string into a document XmlDocument doc = new XmlDocument(); doc.LoadXml("<test id='' />"); //Obtain the string...
4
by: Derek Martin | last post by:
I have an object with several string elements that I would like to check for invalid characters in the properties of each element. Can I use string.replace to do that or is there a better...
11
by: jarod1701 | last post by:
Hi, i'm currently trying to replace an unknown string using regular expressions. For example I have: user_pref("network.proxy.http", "server1") What do I have to do to replace the...
2
by: Neeta | last post by:
Hi All, I am having problem using Regex.Replace.I am trying to search all the strings present in a .cs file and replace it with a different string .I am doing this by searching all the code...
6
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello, I have some XML that is returned to my application from another vendor that I cannot change before it gets to me. I can only alter it after it gets to my application. That being said, I...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.