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

How to change & to & in string?

P: n/a
All,

I receive an xml doc with an element which contains a & in the data. I
am attempting to insert the data into a SQL Server database and I want to
convert the & to a "&" character before I perform the insert. Is the a
way in VB.NET to perform this?

-Rich
Nov 11 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Rich Wallace wrote:
I receive an xml doc with an element which contains a & in the data. I
am attempting to insert the data into a SQL Server database and I want to
convert the & to a "&" character before I perform the insert. Is the a
way in VB.NET to perform this?

I'm wondering how do you get &? I mean how do you read that data?
Anyway, here is C# code:
string str = "A&B";
string str2 = str.Replace("&", "&");
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #2

P: n/a
Thanks Oleg,

I receive teh data when I read the XML file in by using XmlTextReader. I'll
give your example a try and see what happens.

-Rich

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:em**************@TK2MSFTNGP10.phx.gbl...
Rich Wallace wrote:
I receive an xml doc with an element which contains a &amp; in the data. I am attempting to insert the data into a SQL Server database and I want to convert the &amp; to a "&" character before I perform the insert. Is the a way in VB.NET to perform this?

I'm wondering how do you get &amp;? I mean how do you read that data?
Anyway, here is C# code:
string str = "A&amp;B";
string str2 = str.Replace("&amp;", "&");
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #3

P: n/a
Rich Wallace wrote:
Worked great! If I have more than one instance of the text that I want to
replace, will it pick up all instances in the string or just the first one
it finds?

No, it's classical substring replacement, whenever substring is matched it's
replaced with another substring (second argument).
I'm still wondering, how do you get &amp; in XmlTextReader, probably via
ReadInnerXml() method? Actually if you need string value (not XML fragment) as
value you can read it using Value property or ReadElementString() method -
then you don't have to bother about such XML-syntax-specific stuff like
escaping & etc - all will be done by XmlReader.

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #4

P: n/a
Rich Wallace wrote:
Yes, I'm using ReadInnerXML.

And do you expect to read XML fragment or just string value?
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #5

P: n/a
Now that I'm digging into it, just the string, so I guess I can chage the
way I extract the data then.

"Oleg Tkachenko" <oleg@NO_SPAM_PLEASEtkachenko.com> wrote in message
news:%2******************@TK2MSFTNGP12.phx.gbl...
Rich Wallace wrote:
Yes, I'm using ReadInnerXML.

And do you expect to read XML fragment or just string value?
--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Nov 11 '05 #6

P: n/a
you can do something like this....

reference System.Web.dll in project (if WinForm)

declare the innerXml text as a string, then

string.replace(HtmlEncode("&"), "&")


"Rich Wallace" <ri**********@jfshea.com> wrote in message
news:eB****************@TK2MSFTNGP11.phx.gbl...
All,

I receive an xml doc with an element which contains a &amp; in the data. I am attempting to insert the data into a SQL Server database and I want to
convert the &amp; to a "&" character before I perform the insert. Is the a way in VB.NET to perform this?

-Rich

Nov 11 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.