Click here to Skip to main content
15,905,616 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
VB
If ifBlank(XMLStr, "") = "" Then Return "" : Exit Function
        XMLStr = XMLStr.Replace("&", "&")
        XMLStr = XMLStr.Replace("<", "&lt;")
        XMLStr = XMLStr.Replace(">", "&gt;")
        Dim str As Char = <string>"</string>
        XMLStr = XMLStr.Replace(str, "&quot;")
        XMLStr = XMLStr.Replace("'", "&apos;")
        Return XMLStr


[EDIT] fixed HTML encoding, assuming going from "regular" to "encoded". [/EDIT]
Posted
Updated 18-Mar-13 8:36am
v4
Comments
Richard MacCutchan 16-Mar-13 7:11am    
And what is your problem?
Sushantkjha 16-Mar-13 7:21am    
i need this line of code in C#..bcz i have written this code in C# i am facing problem in
Dim str As Char = <string>"
XMLStr = XMLStr.Repalce(str,""") ..plz

What is that code supposed to do, exactly?
All you have is a sequence of calls to String.Replace with the two parameters the same: so they will replace a substring with the same substring, and do nothing at all in practice.
For example, if I have the string
hello&there
and I do this:
VB
XMLStr = "hello&there"
XMLStr = XMLStr.Replace("&", "&")
Then I end up with
hello&there
And the call to replace has done a total on nothing.

So what are you trying to do? Because if you are trying to do HTML enocding to replace tag with printable ones in a web page, then you would be better off using Server.HTMLEncode which will do the job for you...
 
Share this answer
 
If I understand your dilemna, you want this code:

Dim str As Char = <string>"
XMLStr = XMLStr.Replace(str, """)

in equivalent C#, which is:

XMLStr = XMLStr.Replace("\"", """);

HTMLEncode is the proper solution to the larger problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900