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 4 24337
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(???,""")
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
"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(???,""")
'... = strFoo.Replace("""", """)'.
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
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 " 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(???,""")
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
Kevin,
In addition to the other comments, you can use also ControlChars.Quote. strFoo = strFoo.replace(ControlChars.Quote,""")
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(???,""")
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: middletree |
last post by:
What's wrong with this code?
strLongDesc =
Replace(Replace(Replace(Replace(Trim(Request.Form("LongDesc")),"'","''"),vbC
rLf,"<br>"),"<",<),"<",>)
Background:
This field is a textarea, and I...
|
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(...
|
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...
|
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?
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |