I'm trying to find a way to replace special characters (<, >, &, ', ") in my description field with the escape sequences, so I can use the newString in a string, that is later on use to generate a xml file.
The problem is when I try to put the line with ampersand into the code, it gives a weird string like this:
when it should look like this.
With the character <, > and ' it works prefectly fine.
Is there a way to resolve this matter with a different approach?
Code:
Const SpecialCharacters As String = "<,>,',&" 'modify as needed
Dim myString As String
Dim newString As String
Dim char As Variant
myString = rs![desc]
newString = myString
For Each char In Split(SpecialCharacters, ",")
newString = Replace(newString, "<", "<")
newString = Replace(newString, ">", ">")
newString = Replace(newString, "'", "'")
newString = Replace(newString, "&", "&") '#ampersand line, tried with #amp; also
Next
The problem is when I try to put the line with ampersand into the code, it gives a weird string like this:
Code:
<ItemDesc>Test &#38;#38;lt; &#38;#38;gt; &#38;#38;#39; &#38;#38;</ItemDesc>
when it should look like this.
Code:
<ItemDesc>Test < > & </ItemDesc>
With the character <, > and ' it works prefectly fine.
Is there a way to resolve this matter with a different approach?
Last edited: