?
Solved

How do I replace "&" in vb6?

Posted on 2003-02-22
7
Medium Priority
?
912 Views
Last Modified: 2008-03-10
hi, I know that

strFormattedString = Replace(strUnformattedString, Chr(39), "")
  GetCleanString = strFormattedString

will replace an apostrophe with a blank, but is there a # that will replace an ampersand?   My XML document is not happy with them in it...  
  Thanks in advance!

 -Al
0
Comment
Question by:afeld
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:Chuckie_Ice
ID: 8000821
just do this:

strFormattedString = Replace(strUnformattedString, "&" ,"")
 GetCleanString = strFormattedString
0
 
LVL 2

Expert Comment

by:Chuckie_Ice
ID: 8000871
to answer this in the way your looking for, & = 38

strFormattedString = Replace(strUnformattedString, Chr$(38), "")
GetCleanString = strFormattedString

Also, i used Chr$(38) instead of Chr(38),this may help
0
 
LVL 4

Accepted Solution

by:
CareyJ earned 200 total points
ID: 8001288
'&' is an XML entity.  If you want to write it into your string you'll need to escape it like this:

strFormattedString = Replace(strUnformattedString, Chr(38), "&")

Here are some other XML entities that you might have problems in XML strings:

> = >
< = &lt;
" = &quot;
' = &apos;
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 8001891
hearing...
0
 
LVL 3

Expert Comment

by:Hornet241
ID: 8002301
I have had to do the same thing and CareyJ has the right answer.

0
 
LVL 5

Expert Comment

by:Rhaedes
ID: 8002750
At the moment your XML is just complaining about the ampersand, so you can do a replace as others have said.

If, however, there is any chance that other characters might pop up in the future (foreign names, quotation marks etc), a global solution is to replace all these 'dodgy characters' in the XML with entities (numeric or otherwise) using the free tidy.dll

http://perso.wanadoo.fr/ablavier/TidyCOM/

Rhaedes
0
 

Author Comment

by:afeld
ID: 8004249
Thanks, that is a big help!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question