473,382 Members | 1,348 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,382 software developers and data experts.

How to change & to & in string?

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

Similar topics

12
by: Sammy | last post by:
Hi, my mind is going crazy. I have tried everything I can think of to no avail. I have tried Disable Output Escaping. I tried to think of a way of enclosing the attribute data in a CDATA...
11
by: BoonHead, The Lost Philosopher | last post by:
I think the .NET framework is great! It's nice, clean and logical; in contradiction to the old Microsoft. It only saddens me that the new Microsoft still doesn't under stand there own...
17
by: orekinbck | last post by:
Hi There Say I want to check if object1.Property1 is equal to a value, but object1 could be null. At the moment I have code like this: if (object1 != null) { if (object1.Property ==...
3
by: divya | last post by:
Hi, I have a table tblbwday with 2 fields Name and Birthday.I have written this script for displaying evryday names of the people on that day. <% set objConn...
4
by: SteveT | last post by:
I am trying to create a dataset from an XML file. When calling myDataSet.ReadXml("sample.xml") the code produces an exception error. The XML file has many strings that identify pnp ids on a...
4
by: Scott | last post by:
In order to give a meaning average value and minimum and maximum values, I would like to have a formula for a group of data after taking out those extremes. Can someone share your way to...
3
by: raghu sunkara | last post by:
Hi, How Can i Change or Modify Embedded String Resource In An Assembly. I Need To Modify Embedded String Resource In An Assembly. Please Help Me. Thanks Raghu.
1
by: raghu sunkara | last post by:
hi, how to change or modify embedded string resource in an assembly at runtime. please help me. Thanks, Raghu
3
by: gg | last post by:
I specify the Url element as <xsd:element name="Url"> <xsd:simpleType> <xsd:restriction base="xsd:string"> <xsd:maxLength value="512"/> <xsd:pattern value="http://+"/> </xsd:restriction>...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
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 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.